av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python - 小白django提交數(shù)據(jù)后,沒(méi)有存儲(chǔ)到數(shù)據(jù)庫(kù)(查閱資料并沒(méi)有發(fā)現(xiàn)問(wèn)題)

瀏覽:119日期:2022-07-31 08:33:57

問(wèn)題描述

views.py

#提交評(píng)論def comment_post(request): try:if request.method == ’POST’: comment_form = CommentForm(request.POST) print(comment_form) print(comment_form.is_valid())if comment_form.is_vaild():#驗(yàn)證表單 #獲取表單信息 comment = Comment.objects.create(username=comment_form.cleaned_data['author'], email=comment_form.cleaned_data['email'], url=comment_form.cleaned_data['url'], content=comment_form.cleaned_data['comment'], article_id=comment_form.cleaned_data['article'], user=request.user if request.user.is_authenticated() else None) print(’comment:’,comment) comment.save()else: return render(request,’failure.html’,{’reason’:comment_form.errors}) except Exception as e:logger.error(e) return redirect(request.META[’HTTP_REFERER’])#HTTP_REFERE是header的一部分,瀏覽器向服務(wù)器發(fā)送請(qǐng)求的時(shí)候,告訴服務(wù)器我是從哪里過(guò)來(lái)的

urls.py

from django.conf.urls import urlfrom blog_project.views import *urlpatterns = [ url(r’^$’,index,name=’index’), url(r’^archive/$’,archive,name=’archive’), url(r’^article/$’,article,name=’article’), url(r’^comment/post/$’,comment_post,name=’comment_post’), url(r’^logout$’,do_logout,name='logout'), url(r’^reg’,do_reg,name=’reg’), url(r’^login’,do_login,name=’login’), url(r’^category/$’,category,name=’category’)]

forms.py

class CommentForm(forms.Form): ’’’ 評(píng)論表單 ’’’ author = forms.CharField(widget=forms.TextInput(attrs={'id':'author','class':'comment_input','required':'required','size':'25','tabindex':'1'}), max_length=50,error_messages={'required':'username不能為空',}) email = forms.EmailField(widget=forms.TextInput(attrs={'id':'email','type':'email','class':'comment_input','required':'required','size':'25','tabindex':'2'}), max_length=50,error_messages={'required':'email不能為空',}) url = forms.URLField(widget=forms.TextInput(attrs={'id':'url','type':'url','class':'comment_input','size':'25','tabindex':'3'}), max_length=100,required=False) comment = forms.CharField(widget=forms.Textarea(attrs={'id':'comment','class':'message_input','required':'required','cols':'25','rows':'5','tabindex':'4'}),error_messages={'required':'評(píng)論不能為空',}) article = forms.CharField(widget=forms.HiddenInput())

article.html

<form action='{% url ’comment_post’ %}' method='post'>{% csrf_token %}<p>{{comment_form.author}} <label for='author'>Name<span style='color:red;'>*</span></label></p><p>{{comment_form.email}} <label for='email'>Email(Will NOT be published)<span style='color:red;'>*</span></label></p><p>{{comment_form.url}} <label for='url'>URL</label></p><p> {{comment_form.comment}}</p><p> {{comment_form.article}} <input name='submit' type='submit' tabindex='5' value='確認(rèn)' /></p> </form>

問(wèn)題解答

回答1:

一步一步排查,1表單是否提交數(shù)據(jù)到服務(wù)端,2把服務(wù)端的sql語(yǔ)句打印出來(lái)直接在數(shù)據(jù)庫(kù)里面執(zhí)行看看是否有錯(cuò)誤。

標(biāo)簽: Python 編程
主站蜘蛛池模板: 日韩三级中文字幕 | 日日操视频 | 一级做a爱片性色毛片 | 久久久婷婷 | 九九视频免费观看 | 亚洲色在线视频 | 久久免费观看视频 | 日本欧美视频 | 精品福利在线观看 | 在线观看的av网站 | 青娱乐av | 九九色影院| 成 人 黄 色 片 在线播放 | 簧片在线免费观看 | 国产在线观看一区二区三区 | 日韩久久视频 | 免费爱爱网站 | 亚洲综合精品 | 久久最新视频 | 国内精品久久久久 | 丁香婷婷六月天 | 日韩精品久久久久久久 | 三年中文在线看免费观看 | 在线视频黄 | 一级片免费网站 | 国产三级黄色片 | 怡红院久久 | 又色又爽又黄18网站 | 国产黄a三级三级看三级 | 亚洲二区视频 | 亚洲男人天堂网 | 一区二区三区中文字幕 | 精品在线免费视频 | 婷婷久久五月天 | 手机av在线 | 免费av不卡| 狠狠草视频 | 黄视频免费看网站 | 另类小说第一草 | 日日操夜夜 | 黄色免费一级片 |