这看起来像是一个非常简单的问题,但我无法使其工作。如果@login_required
装饰器出现在特定的视图函数中,则django注册将传入正确的?next=.....
。一旦用户登录,用户将被重定向到他想查看的页面。这很好,工作正常。登录后无法将django注册重定向到?下一个
我的问题是我有这个html页面,不需要登录,但如果你想登录,我有一个<a href='{% url auth_login>
目前。如果用户从此html登录,则?next=
会显示一个空白并被重定向到默认位置accounts/profile/
。我还没有设置用户配置文件,所以我得到一个TemplateDoesNotExist
错误。
我有这样的事情:
views.py
...
def display_all(request):
response = list_detail.object_list(
request,
queryset = MyModel.objects.all(),
template_name = 'show_all.html'
)
return response
-
show_all.html
<html>
<head>
<title> Display Everything </title>
</head>
<body>
<a href='{% url auth_login %}?next={{ request.path }}'>Login</a>
<h1> Displaying all items! </h1>
<ul>
{% for item in object_list %}
<li> {{ item.name }} </li>
{% endfor %}
</ul>
</body>
</html>
在这里,我通过列举出来展示的一切,我在顶部的登录链接,如果你想登录。 {{ request.path }}
返回一个空字符串,所以我得到的最终结果是http://localhost:8000/accounts/login/?next=
,它将重定向到默认accounts/profile/
。