0

I have a view that has a decorator which redirects to admin login page as following

@login_required(login_url='/admin')

That means whenever a user tries to access /admin/some/url/ he will be asked to login through admin page at /admin/?next=/admin/some/url/

My question is: how do I handle redirecting after the user has logged in via the admin page?

/admin/?next=/admin/some/url/ -> /admin/some/url/

I assume that I need to tweak my app's urlpatterns and use redirect_to from

django.views.generic.simple

and overwrite

(r'^admin/', include(admin.site.urls))

P.S: To simplify this question: I need a regex to match /admin/some/url/ in /admin/?next=/admin/some/url/ so I can use it for my redirect_to function

Nam Ngo
  • 2,093
  • 1
  • 23
  • 30
  • Does this answer your question? [http://stackoverflow.com/questions/523356/python-django-page-redirect][1] [1]: http://stackoverflow.com/questions/523356/python-django-page-redirect – super9 Nov 26 '11 at 10:24
  • Er, why? What does this have to do with regexes? – Daniel Roseman Nov 26 '11 at 12:55
  • @DanielRoseman what I meant was to use regex to match whatever is after /admin/?next= and redirect_to the matched value. Unless you have a better option? – Nam Ngo Nov 26 '11 at 15:03

1 Answers1

0

I'd recommend to not use the admin stuff to manage user authentication.

See the Django documentation about Authentication Views, this is really easy and automatically does the right thing with the next parameter.

Probably this didn't exist yet when you asked the question nine years ago :-)

Uwe Kleine-König
  • 3,426
  • 1
  • 24
  • 20