Ticket #8022: simple.patch
File simple.patch, 1.3 KB (added by , 16 years ago) |
---|
-
simple.py
1 1 from django.template import loader, RequestContext 2 from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone 2 from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone,HttpResponseRedirect 3 3 4 4 def direct_to_template(request, template, extra_context=None, mimetype=None, **kwargs): 5 5 """ … … 17 17 t = loader.get_template(template) 18 18 return HttpResponse(t.render(c), mimetype=mimetype) 19 19 20 def redirect_to(request, url, **kwargs):20 def redirect_to(request, url, permanent=True, **kwargs): 21 21 """ 22 22 Redirect to a given URL. 23 23 … … 30 30 ) 31 31 32 32 If the given url is ``None``, a HttpResponseGone (410) will be issued. 33 If permanent is True, the return code will be 301 - Moved Permanently, 34 otherwise, the return code will be 302 - Found. 33 35 """ 34 36 if url is not None: 35 return HttpResponsePermanentRedirect(url % kwargs) 37 if permanent: 38 return HttpResponsePermanentRedirect(url % kwargs) 39 else: 40 return HttpResponseRedirect(url % kwargs) 36 41 else: 37 42 return HttpResponseGone()