Opened 17 years ago

Last modified 14 years ago

#6581 closed

django.contrib.auth.views.redirect_to_login isn't a view — at Version 4

Reported by: steve_cassidy51 Owned by: nobody
Component: contrib.auth Version: dev
Severity: Normal Keywords: auth redirect_to_login
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description (last modified by Ramiro Morales)

The documentation lists redirect_to_login as a view alongside password_change etc but the definition doesn't take a 'request' first argument and so doesn't work properly as a view. Eg. if I use it in urls.py:

 (r'^$', 'django.contrib.auth.views.redirect_to_login', {'next': '/something'})...

then I get an error that 'next' is provided twice since the first arg supplied to the view
is the request object. If I leave out 'next' then I get a huge long URL in the redirect that contains the entire request serialised.

So, either this should be made into a view with the addition of the request parameter or it should be removed from the list of views in the documentation.

Change History (6)

comment:1 by Pete Crosier, 17 years ago

Has patch: set
Keywords: redirect_to_login added
Triage Stage: UnreviewedDesign decision needed

Simplest case patch attached, though I guess changing this has the potential to break things for a lot of people?

by Pete Crosier, 17 years ago

Added request to redirect_to_login

comment:2 by Thomas Güttler, 17 years ago

Yes, that's true. It is not a view.

As far as I understand it, it redirects you to login, even if you are already logged in.

Why is redirect_to_login needed at all?

related: #6306

comment:3 by Thomas Güttler, 17 years ago

I thought about this again. I guess redirect_to_login is older than reverse(). I think it should be removed and all calls to this
method should be replaced with calls to reverse():

tilldu@r51:~/_django/django$ find -name '*.py' | xargs grep 'redirect_to_login'
./views/generic/create_update.py:from django.contrib.auth.views import redirect_to_login
./views/generic/create_update.py:        return redirect_to_login(request.path)
./views/generic/create_update.py:        return redirect_to_login(request.path)
./views/generic/create_update.py:        return redirect_to_login(request.path)
./contrib/auth/views.py:def redirect_to_login(next, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
./contrib/flatpages/views.py:        from django.contrib.auth.views import redirect_to_login
./contrib/flatpages/views.py:        return redirect_to_login(request.path)

Since create_update needs to be rewritten for newforms, only one call is left: views.py of flatpages.

comment:4 by Ramiro Morales, 16 years ago

Description: modified (diff)

by steve_cassidy51, 16 years ago

Attachment: redirect_to_login_doc.diff added

modify documentation to warn that this is not a view

Note: See TracTickets for help on using tickets.
Back to Top