一个潜在的BUG
在添加博客一章中,点击提交向函数addArticle提交数据,数据存入数据库之后执行跳转,课程所说是跳转到index页面,但实际并没有,如果我们在跳转后的文章页面刷新,则再一次提交form表单,这时哪里出了问题?还有,代码不顾严谨,思路严谨一点应该这样做:前端使用js检测文章标题和内容是否为空,只要其中一个为空则不能提交表单。
def addArticle(request):
#get form table request value
title = request.POST.get('title',"TITLE")
content = request.POST.get('content',"CONTENT")
# write data to the database
models.Article.objects.create(title=title,content=content)
# add success back index page
articles = models.Article.objects.all()
return render(request,"blog/index.html",{'articles':articles})