Last active
June 19, 2016 17:25
-
-
Save uolot/4171107 to your computer and use it in GitHub Desktop.
Django named url RedirectView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# views.py | |
from django.views.generic import RedirectView | |
from django.core.urlresolvers import reverse | |
class NamedUrlRedirectView(RedirectView): | |
def __init__(self, url, *args, **kwargs): | |
self.url = reverse(url) | |
super(NamedUrlRedirectView, self).__init__(*args, **kwargs) | |
# in urls.py | |
(r'^blog/category/pictures/$', NamedUrlRedirectView().as_view(url='gallery-index')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@eugena: It was added in Django 1.6, while when the gist was create, Django's current version was 1.4. Nowadays it's definitely the correct solution :)