0

I want to have my custom "/login" page. So in settings.py I did a simple LOGIN_URL = '/login'. But before doing it, I want to develop all other more complex pages. I found a simple but very effective hack like this:

urlpatterns = [ # blabla url(r'^admin/', include(admin.site.urls)), url(r'^login/$', RedirectView.as_view( url=reverse_lazy('admin:login'))), # blabla ] 

This means: when the user is not connected he/she is redirected to /login. In the urls, /login is converted to 'admin:login' which is admin/login. This is a "double" redirect. Everthing works fine except this:

  • origin URL: "/my_jobs"
  • redirected to "login?next=/my_jobs"
  • redirected to "/admin/login"

So my problem is that I want do pass again the "next" parameter in the RedirectView. I found a lot about redirection and custom login, but not something about that on stackoverflow (this is not a duplicate).

1 Answer 1

1

You can set query_string to True, so that query strings are appended to the URL.

RedirectView( url=reverse_lazy('admin:login'), query_string=True, # You might want to set permanent=False, # as it defaults to True for Django < 1.9 permanent=False, ) 

Note that Django comes with a built in login view. You can enable it by adding the URL pattern and a simple template, which isn't much more work than your code above.

Sign up to request clarification or add additional context in comments.

2 Comments

It's that simple... i've been fighting for that for 2 hours now... thank you very much
I would use the built in logout view rather than trying to redirect to the admin logout view.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.