【发布时间】:2020-07-13 06:39:12
【问题描述】:
我想将此错误传递给模板,但它不起作用,
def addcomment(request):
name = request.POST['name']
comment = request.POST['comment']
if name=="" and comment=="":
my_dict = {'error':'blank fields not allowed'}
return redirect('home',my_dict)
Comment(name = request.POST['name'],comment = request.POST['comment']).save()
return HttpResponseRedirect('/')
【问题讨论】:
-
重定向使浏览器向另一个视图发出另一个请求。这可以由不同的服务器处理。要跨多个请求传递消息,请使用 django messages framework。
-
是的,它的工作原理:),它有办法在添加到消息后删除消息吗?
标签: python html django web backend