【发布时间】:2017-10-03 10:06:46
【问题描述】:
我是 python 和 web2py 的新手,我一直在创建一个输入 csv 文件的表单和导入 csv 文件的代码。
这是我的简单代码
模型 = 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'
)
CONTROLLER = 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 文件并创建代码来输入在“csvfile”标题中具有相同标题的 csv 文件
帮帮我,谢谢!
【问题讨论】: