0
即時通訊新的python和web2py,我卡在創建一個窗體輸入csv文件和導入csv文件的代碼。如何將CSV導入到web2py表中?
這裏是我的簡單的代碼
模型= db_tables.py
# -*- coding: utf-8 -*-
db = DAL('sqlite://storage.sqlite')
db.define_table('csvfile',
Field('nomor','integer'),
Field('nama'),
Field('umur','integer'),
migrate=False,
format = '%(name)s'
)
控制器= default.py
@auth.requires_login()
def index():
grid = SQLFORM.grid(db.csvfile, user_signature = False)
response.flash = T("Hello World")
return locals()
#def import_csv():
# form = FORM('Value:', INPUT(_value = 'name'), INPUT(_type = 'submit'))
# db.csvfile.import_from_csv_file(open('filename.csv'))
# return dict(form = form)
def import_csv():
form = FORM(INPUT(_type = 'file', _name = 'csv_file'),
INPUT(_type = 'submit', _value = T('Import')))
return(form=form)
VIEWS =默認/ index.html的
{{left_sidebar_enabled,right_sidebar_enabled=False,('message' in globals())}}
{{extend 'layout.html'}}
<table>
<tr>{{=form}}
<td>{{pass}}
</td>
</tr>
</table>
其實我已經顯示錶,但我不能做一個表格輸入CSV文件,並創建一個代碼,以輸入CSV文件與'csvfile'標題相同的頭文件
幫助我,謝謝!