国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Django form Form.save() issue - Stack Overflow
伊謝爾倫
伊謝爾倫 2017-05-24 11:34:50
0
2
1042
def commentCreate(request, articleId):    
#POST
'''
the problem is  comment no relate mapping to one id of Artilce
    單純的將CommentForm().save 是無法實現(xiàn)留言的,因為
    創(chuàng)建一個留言需要對應(yīng)一個文章,即要對應(yīng)其文章所屬id;
'''
content = request.POST.get('comment')

CommentForm.content = content


comment = CommentForm()    
#print ('表單綁定確認(rèn):',comment.is_bound)
'''
if not comment.is_valid():
    return render(request, template,{'article':articleId})
'''
comment.save()
messages.success(request,'留言已新增')
return redirect('article:articleRead',articleId=articleId)

Console錯誤:
django.db.utils.IntegrityError: 錯誤:  在字段 "article_id" 中空值違反了非空約束
DETAIL:  失敗, 行包含(879, , null, 2017-05-22 11:05:06.862614+00, null).


網(wǎng)頁錯誤:
    comment.save() ...
▼ Local vars
Variable    Value
articleId    
'336'
comment    
<CommentForm bound=False, valid=False, fields=(content)>
content    
'你好'
request    
<WSGIRequest: POST '/article/commentCreate/336/'>

Bagaimana untuk meletakkan nilai articleId yang sepadan dengan artikel ke dalam CommentForm()?

伊謝爾倫
伊謝爾倫

小伙看你根骨奇佳,潛力無限,來學(xué)PHP伐。

membalas semua(2)
劉奇

Dapatkan Artikel berdasarkan articleId: obj = Article.objects.get(id=articleId)
Kemudian komen.article = obj # Bergantung pada nama medan artikel yang anda takrifkan dalam model

phpcn_u1582

Baiklah, terima kasih, saya telah menemui penyelesaian untuk masalah ini di http://zmrenwu.com/post/14/. Tetapi bagaimana saya boleh memadamkan soalan dari forum ini?

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan