Last Updated: February 25, 2016
· tim_heap

Django URL redirect shortcut

Redirect from to another named URL, without having to create a whole new view:

from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect

def lazy_redirect(name, args=None, kwargs=None,
    Make a redirect view directly from ``.
    Takes the same arguments as
    `django.core.urlresolvers.reverse`, with an
    additional argument `http_response`. Use
    `http_response` to change the HttpResponse class
    used in the redirect. It defaults to

    def redirect(_):
        destination = reverse(name,
        return http_response(destination)

    return redirect

urlpatterns = patterns('',
    url(r'^redirect-me/$', lazy_redirect(
        kwargs={'name': 'landing-page.html'})