Site menu

CodeCook.io

  • Languages
    • C
    • C++
    • CSS
    • Git
    • HTML
    • Java
    • JavaScript
    • jQuery
    • PHP
    • Python
    • Ruby
    • Scala
  • redirect
  • url

Django - Django redirect directly in urls.py

Redirect a url to another url directly in the urls.py file using name matching.

Pattern name of redirect target
0
1788
  • Share on Facebook
  • Share on Google+
  • Share on Twitter

RedirectView Django 1.6

Use class based RedirectView with url name parameter. Possibly use permanent=True for a permanent redirect.

from django.views.generic import RedirectView

urlpatterns = patterns('',
    url(r'{{pattern}}', RedirectView.as_view(pattern_name='{{redirect_name}}')),
)
c

Notes

  • Django >= 1.6

last update: Oct. 28, 2014

Advertisement

This project is hosted on DigitalOcean, try it and support us

Related concept

  • Django get domain current request

Random task

  • Box-sizing
  • List existing tags
  • Test list of booleans all true
  • Create new repository
  • Get template directory
  • Blog
  • About
  • License