#8022 closed (fixed)
Extend django.views.generic.simple.redirect_to to support permanent or temporary redirect codes
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Generic views | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Design decision needed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
It's possible that this is completely inappropriate, but I've extended django.generic.simple.redirect_to with an extra, optional argument, 'permanent'.
By default, redirect_to returns a 301 return code, but if permanent=True is specified, it'll return a 302 instead.
Alternatively, a new generic view function, say temporary_redirect_to, could also do the same thing.
Index: simple.py =================================================================== --- simple.py (revision 8135) +++ simple.py (working copy) @@ -1,5 +1,5 @@ from django.template import loader, RequestContext -from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone +from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone,HttpResponseRedirect def direct_to_template(request, template, extra_context=None, mimetype=None, **kwargs): """ @@ -17,7 +17,7 @@ t = loader.get_template(template) return HttpResponse(t.render(c), mimetype=mimetype) -def redirect_to(request, url, **kwargs): +def redirect_to(request, url, permanent=True, **kwargs): """ Redirect to a given URL. @@ -30,8 +30,13 @@ ) If the given url is ``None``, a HttpResponseGone (410) will be issued. + If permanent is True, the return code will be 301 - Moved Permanently, + otherwise, the return code will be 302 - Found. """ if url is not None: - return HttpResponsePermanentRedirect(url % kwargs) + if permanent: + return HttpResponsePermanentRedirect(url % kwargs) + else: + return HttpResponseRedirect(url % kwargs) else: return HttpResponseGone()
Attachments (1)
Change History (5)
by , 16 years ago
Attachment: | simple.patch added |
---|
comment:1 by , 16 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|
comment:3 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Hmm, looks like it is now, but wasn't when I opened this ticket in July. Still, done, is done, so I'll close the ticket.
comment:4 by , 16 years ago
Yes, this was apparently added independently without realization that there was a ticket open for it. Happens sometimes.
Patch