Menu Close

How to add a page redirect with Python Django?

Sometimes, we want to add a page redirect with Python Django.

In this article, we’ll look at how to add a page redirect with Python Django.

How to add a page redirect with Python Django?

To add a page redirect with Python Django, we can add a RedirectView.

For instance, we write

from django.views.generic import RedirectView

urlpatterns = patterns('',
    (r'^one/$', RedirectView.as_view(url='/another/')),
)

to create a RedirectView by calling RedirectView.as_view with the url argument set to the URL we want to redirect to.

Conclusion

To add a page redirect with Python Django, we can add a RedirectView.

Posted in Python, Python Answers