我想創建一個使用Web2Py/Python的評論部分,我創建了沒有錯誤的表單,但是當表單提交時註釋並沒有完全添加。任何人都可以發現我錯過的東西嗎?輸入不是從Web2Py/Python表單提交
db1.py模式:
db.define_table('products',
Field('Product_Name',requires=IS_NOT_EMPTY()),
Field('Product_Description',requires=IS_NOT_EMPTY()),
Field('Product_Review',requires=IS_NOT_EMPTY()),
auth.signature)
db.define_table('product_comments',
Field('products', 'reference products'),
Field('body', 'text', requires=IS_NOT_EMPTY()),
auth.signature)
default.py控制器:
def show():
post = db.products(request.args(0, cast=int))
productDescription = T("Product Description")
productReview = T("Product Review")
back = T("Back")
#commentHeading = T("Comments")
db.product_comments.products.default = post.id
db.product_comments.products.readable = False
db.product_comments.products.writable = False
comments = db(db.product_comments.products==post.id).select()
form = SQLFORM(db.product_comments).process()
return locals()
默認/ show.html觀點:
{{extend 'layout.html'}}
<h1>{{=XML(post.Product_Name, sanitize=True)}}</h1>
<h2>{{=XML(productDescription, sanitize=True)}}</h2>
{{=XML(post.Product_Description, sanitize=True)}}
<h2>{{=XML(productReview, sanitize=True)}}</h2>
{{=XML(post.Product_Review, sanitize=True)}}
<h2>Comments</h2>
{{for comment in comments:}}
<div class="well">
{{=comment.created_by.first_name}} {{=comment.created_by.last_name}}
on {{=comment.created_on}} says
{{comment.body}}
</div>
{{pass}}
{{=XML(form, sanitize=True)}}
<a href="/ReviewMyProduct/default/index">{{=XML(back, sanitize=True)}}</a>
就是這樣,我在發表評論時仍然收到錯誤,因爲現在我的first_name不匹配屬性,即使我已經在兩個數據庫上分配了auth.signature。 錯誤:('NoneType'對象沒有屬性'first_name') –