Ticket #8022: simple.patch

File simple.patch, 1.3 KB (added by David Sauve <dnsauve@…>, 7 years ago)

Patch

  • simple.py

     
    11from django.template import loader, RequestContext
    2 from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone
     2from django.http import HttpResponse, HttpResponsePermanentRedirect, HttpResponseGone,HttpResponseRedirect
    33
    44def direct_to_template(request, template, extra_context=None, mimetype=None, **kwargs):
    55    """
     
    1717    t = loader.get_template(template)
    1818    return HttpResponse(t.render(c), mimetype=mimetype)
    1919
    20 def redirect_to(request, url, **kwargs):
     20def redirect_to(request, url, permanent=True, **kwargs):
    2121    """
    2222    Redirect to a given URL.
    2323
     
    3030        )
    3131
    3232    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.
    3335    """
    3436    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)
    3641    else:
    3742        return HttpResponseGone()
Back to Top