在 django-registration 中传播 ?next=
我有一个具有 @login_required 装饰器的视图,并且在拉出页面时,如果您没有登录,它确实会将您发送到带有正确的登录表单?next=/url/you/tried/to/see
我的问题是如何将该 ?next 值传递给后续表单和激活电子邮件,以便当用户完成激活过程时,他们将被重定向到他们最初尝试访问的视图。
我的 Python'foo 和 Django'foo 很弱,所以请保留 5 岁孩子可以理解的答案;)
提前谢谢大家。
I have a view that has the @login_required decorator and upon pulling up the page, if you are not logged in it does send you to the login form with the proper ?next=/url/you/tried/to/see
My problem is how to I pass along that ?next value to the subsequent forms and activation email so that when the user completes the activation process they are redirected to the view they originally tried to get to.
My Python'foo and Django'foo is weak, so please keep the answer to something a 5 year old could follow ;)
Thanks all in advanced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
内置视图默认处理此问题。确保您的登录页面模板中有这段代码:
。
Built in view handles this by default. Make sure you have this piece of code:
<input type="hidden" name="next" value="{{ next }}" />
in your template of login page.您可以执行此操作
You can do this
<a href="{% url 'app:sign_up' %}?next={{ next }}">
这很简单,只需保存 url 并编写您自己的后端重写 2 个方法即可。
accounts/models.py
accounts/nextbackend.py:
用户这个^后端作为accounts/views.py中的注册后端:
urls.py:
应该可以工作,没有测试它,即时编写。显然需要添加一些导入。
It's easy, just save the url and write your own backend overriding 2 methods.
accounts/models.py
accounts/nextbackend.py:
user this^ backend as your registration backend in accounts/views.py:
urls.py:
Should work, didn't test it, written on the fly. Obviously will need adding some imports.