def postDataRequest(request):
if request.method == 'POST':
username = request.POST['username']
userid= request.POST['userid']
if(userid== "21310"):
context = {
"result" : Dataengine(username,userid).dataFunc()
}
messages.add_message(request, messages.SUCCESS, context)
return render(request, 'pages/dataresult.html', context)
我通过post请求向用户显示一些数据。我要做的是在用户在'dataresult.html'
页面上看到结果后30秒内重定向'pages/index.html'
。我该怎么做
您可以使用返回重定向(“app:view”)它会将您重定向到下一个视图,如果您想使用上下文值重定向,则可以
1.from django.http导入HttpResponseRedirect
返回HttpResponseRedirect(反向('app:view',context))
或
2。重定向(反向('app:view',context))
因为在django中,不能使用重定向传递参数。您唯一的赌注是将它们作为URL的一部分传递
在模板中,您可以使用以下命令将页面重定向到给定URL:
通过将其添加到模板中的
<head>
隔室中,该隔室由使用dataresult.html
URL激发的视图呈现相关问题 更多 >
编程相关推荐