python - Django 下一页在登录页面中不起作用

标签 python django authentication

我打开浏览器,尝试访问我的 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.loginnext 变量直接传递给模板上下文。 另外,阅读有关 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/

相关文章:

python - Pyenv本地配置问题

python - 多个数组中所有可能的精确总和

django - mod_wsgi 拒绝在项目文件夹内写入日志文件的权限

python - Django 只从模型中添加一个字段

Android 某些设备上的 Flutter local_auth 问题

python - 范围倒计时到零

python - 为什么 1 + 1 不使用 BINARY_ADD?

python - 从 ChoiceField 传递选择不接受

node.js - passport.session() 中间件有什么作用?

authentication - Spring-在所有自定义身份验证提供程序的末尾记录安全冲突