This seems like a really simple problem, but I can't get it to work. django-registration will pass in the correct ?next=.....
if the @login_required
decorator is present in the particular view function. Once the user logs in, the user will be redirected to the page he wanted to look at. This is good and works properly.
My problem is I have this html page that doesn't require login, but if you want to log in, I have an <a href='{% url auth_login>
present. If the user logs in from this html, the ?next=
shows a blank and is redirected to the default location accounts/profile/
. I haven't set up the user profile yet, so I get a TemplateDoesNotExist
error.
I have something like this:
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>
Here, I display everything by listing it out and I have a login link at the top if you want to log in. {{ request.path }}
returns an empty string, so the end result I get is http://localhost:8000/accounts/login/?next=
which will redirect to the default accounts/profile/
.
If you problem is that a request.path is empty, than you need to add a "django.core.context_processors.request" to TEMPLATE_CONTEXT_PROCESSORS in settings.py. Look at django docs