午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

python - Django 表單問題?

瀏覽:209日期:2022-07-16 17:34:23

問題描述

關于Django表單問題先給出models.py和forms.py

圖片描述python - Django 表單問題?

python - Django 表單問題?

再給出views.py的代碼

def articleUpdate(request, articleId):’’’Update the article instance: 1. Get the article to update; redirect to 404 if not found2. Render a bound form if the method is GET3. If the form is valid, save it to the model, otherwise render abound form with error messages’’’articleToUpdate = get_object_or_404( Article, id=articleId)template = ’article/articleCreateUpdate.html’if request.method == ’GET’: print(ArticleForm(instance=articleToUpdate)) articleForm = ArticleForm(instance=articleToUpdate) return render(request, template, {’articleForm’:articleForm, ’article’:articleToUpdate})# POSTarticleForm = ArticleForm(request.POST, instance=articleToUpdate)if not articleForm.is_valid(): return render(request, template, {’articleForm’:articleForm, ’article’:articleToUpdate})articleForm.save()messages.success(request, ’文章已修改’)return redirect(’article:articleRead’, articleId=articleId)def commentCreate(request, articleId): ’’’Create a new article instance1. If method is GET, render an empty form2 . If method is POST, perform form validation. Display error messages if the form is invalid3. Save the form to the model and redirect to the article page’’’template = ’article/commentCreate.html’ articleToUpdate = get_object_or_404( Article, id=articleId) if request.method == ’GET’:return render(request, template,{’commentForm’:CommentForm(), ’article’:articleToUpdate}) # POSTcommentForm = CommentForm(request.POST, instance=articleToUpdate) if not commentForm.is_valid():return render(request, template, {’commentForm’:commentForm(), ’article’:articleToUpdate}) commentForm.save() messages.success(request,’留言已新增’) return redirect(’article:articleRead’,articleId=articleId)

兩則方法是幾乎是一樣的,都是用forms表單,但是我使用的forms表單并不是同一類,一個是ArticleForm一個是CommentForm但是結果出現(xiàn)在views:commentCreate里它的效果是等于articleUpdate,即新增留言變成修改文章內(nèi)容python - Django 表單問題?

python - Django 表單問題?

問題解答

回答1:

表單是類,你取出數(shù)據(jù),為什么不填充到表單中。

else:form = CommentsForm(request.POST)if form.is_valid():

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 可以免费看的av | 国产少妇精品 | 国产三级视频在线播放 | 看全色黄大色黄大片大学生 | 国产午夜免费视频 | 国产亚洲福利 | 亚洲精品一级片 | 日本aⅴ在线观看 | 国产h视频在线观看 | 欧美日韩网 | 久操视频在线播放 | 国内精品久久久久久久 | 亚洲成人一区二区三区 | 久久国产免费观看 | 男人天堂手机在线 | 在线视频 亚洲 | 伊人影院视频 | 亚洲一区二区三区影院 | 毛片网站免费观看 | 一级片一级片一级片 | 亚洲三级精品 | 日韩小视频在线 | 二区三区在线 | 亚洲激情视频在线播放 | 久久综合色88 | 国产一区在线免费观看 | 久久久久久中文字幕 | 蜜桃成人免费视频 | 久久久国产精品x99av | 国产成人福利在线 | 日本黄色大片在线观看 | 日韩欧美视频免费观看 | 国产午夜精品久久久久久久久 | 亚洲天堂男人的天堂 | 中文字幕亚洲视频 | 国产精品久久久一区 | 欧美日韩中文字幕视频 | 在线亚洲精品 | 99爱免费视频 | 亚洲无线视频 | 日本久久精品 |