我打开浏览器,尝试访问我的 Django 站点。我退出了我的帐户,因此我被重定向到我的登录页面,我将要访问的页面作为 GET 参数。
http://website.com/login/?next=/customer/7/54
但是,当我输入登录信息时,我被重定向到:
http://website.com/
尽管如此,我正在努力:
http://website.com/customer/7/54
/customer/7/54 指向一个确实有 @login_required 装饰器的 View ,但我假设它在我登录后仍然指向那个 View 。这是怎么回事?
编辑:所以我意识到,我有一个隐藏的输入标签:
<input type="hidden" name="next" value='/'>
但是,如何将 GET 参数 '/customer/7/54/传递到登录模板中?
最佳答案
根据您编辑的问题,您可以在登录页面获取下一个参数,如下所示:
<input type="hidden" name="next" value="{{ next }}">
标准 django 的 django.contrib.auth.views.login
将 next
变量直接传递给模板上下文。
另外,阅读有关 user authentication 的文档:
You can also specify the name of the GET field which contains the URL to redirect to after login by passing redirect_field_name to the view. By default, the field is called next.
但是您可能不需要更改它。
关于python - Django 下一页在登录页面中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12536709/