﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
8022	Extend django.views.generic.simple.redirect_to to support permanent or temporary redirect codes	David Sauve <dnsauve@…>	nobody	"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()
}}}"		closed	Generic views	dev		fixed			Design decision needed	1	0	0	0	0	0
