django重定向到查看 [英] django redirect to view

查看:99
本文介绍了django重定向到查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,我想要做一些事情,然后重定向到另一个视图与成功消息。我要重定向到的方法的签名是

I have one view that I want to do some stuff in and then redirect to another view with a success message. The signature of the method that I want to redirect to is

quizView(request, quizNumber, errorMessage=None, successMessage=None): 

我尝试重定向到该视图如下:

and my attempt at redirecting to that view looks like this:

return redirect(quizView, quizNumber=quizNumber, errorMessage=None, successMessage="Success!")

我已经尝试了大多数命名和未命名参数的组合,我无法让它做我想做的事。有没有办法让这个工作?

I've tried most every combination of named and un-named paramaters and I can't get it to do what I want. Is there a way to make this work?

另外,我尝试用第一个视图返回第二个视图但是后面的URL仍然是旧视图中的位置而不是看起来好像已经重定向。

Also, I tried just returning the the second view with the first but then the URL is still where it was in the old view instead of appearing as though it has redirected.

谢谢!

推荐答案

您没有为URL指定名称,因此您需要使用视图功能的整个路径。另外,该URL不接受 errorMessage successMessage 参数,因此将它们放入反向调用将失败。这就是你想要的:

You haven't given your URL a name, so you need to use the whole path to the view function. Plus, that URL doesn't take errorMessage or successMessage parameters, so putting them into the reverse call will fail. This is what you want:

return redirect('quizzes.views.quizView', quizNumber=quizNumber)

这篇关于django重定向到查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆