#6581 closed Cleanup/optimization (fixed)
django.contrib.auth.views.redirect_to_login isn't a view
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 )
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.
Attachments (2)
Change History (13)
comment:1 by , 17 years ago
Has patch: | set |
---|---|
Keywords: | redirect_to_login added |
Triage Stage: | Unreviewed → Design decision needed |
by , 17 years ago
Attachment: | 6581.django.contrib.auth.views.diff added |
---|
Added request to redirect_to_login
comment:2 by , 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 , 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 , 16 years ago
Description: | modified (diff) |
---|
by , 16 years ago
Attachment: | redirect_to_login_doc.diff added |
---|
modify documentation to warn that this is not a view
comment:5 by , 16 years ago
Added a patch to change the documentation pointing out
that this is not a view - this might be a less troubling
change to make at the moment.
It does seem like a useful shortcut function, it just
doesn't really belong in views.py.
comment:6 by , 14 years ago
Component: | Contrib apps → contrib.auth |
---|
comment:7 by , 14 years ago
Type: | → Cleanup/optimization |
---|
comment:8 by , 14 years ago
Easy pickings: | unset |
---|---|
Needs documentation: | set |
Patch needs improvement: | set |
Severity: | → Normal |
Triage Stage: | Design decision needed → Accepted |
Move it to a contrib.auth.util
module but import it in views
(with a comment explaining that it's imported for backwards compatibility).
comment:9 by , 14 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
I don't believe introducing yet another util(s) module is needed here. It's really just a documentation issue.
Simplest case patch attached, though I guess changing this has the potential to break things for a lot of people?