为什么我修改文章结果变成新建文章
跟着视频一步步做下来,但是做到这一节时,点击一篇已存在的文章选择修改文章,结果修改完成后变成新建文章,原先的文章没有消失。
跟着视频一步步做下来,但是做到这一节时,点击一篇已存在的文章选择修改文章,结果修改完成后变成新建文章,原先的文章没有消失。
2018-10-31
你的问题解决了吗?我的也是,
def edit_action(request ): title = request.POST.get( 'title', 'TITLE' ) content = request.POST.get( 'content', 'CONTTENT' ) article_id = request.POST.get( 'article.id', '0' ) if article_id == '0': models.Article.objects.create( title=title, content=content ) articles = models.Article.objects.all() return render( request, 'blog/index.html', {'articles': articles} ) article = models.Article.objects.get( pk= article_id) article.title = title article.content = content article.save() return render( request, 'blog/article_page.html', {'article': article} )
就这里出现问题
举报