0
我在一種形式的兩個表格有問題。我使用書中的示例作爲參考,但是我在表單中插入圖像,它上傳文件但URL(圖像名稱)全都是錯誤的,我不知道如何讓它將正確的url作爲圖像名稱。web2py,一種形式的兩個表格,帶圖像上傳
這裏是我的代碼:
db.define_table('forum',
Field('title','string', unique=True, label=T('Title')),
Field('body','text', requires=IS_NOT_EMPTY(),label=T('Body')),
Field('posted_on','datetime',readable=False, writable=False),
Field('posted_by','reference auth_user',readable=False, writable=False),
Field('category',db.category))
db.define_table('doc',
Field('forum_id', 'reference forum',readable=False, writable=False),
Field('image','upload',uploadfolder=os.path.join(request.folder,'uploads'), autodelete=True),
Field('posted_on', 'datetime',default=request.now, readable=False, writable=False),
Field('posted_by','reference auth_user', readable=False, writable=False))
def post():
form=SQLFORM.factory(db.forum,db.doc)
db.forum.posted_on.default =request.now
db.forum.posted_by.default = auth.user
db.doc.posted_on.default = request.now
db.doc.posted_by.default= auth.user
if form.process().accepted:
id = db.forum.insert(**db.forum._filter_fields(form.vars))
form.vars.forum_id=id
id = db.doc.insert(**db.doc._filter_fields(form.vars))
session.flash='Form Posted'
redirect(URL('community'))
redirect
return dict(form=form)