Categories
Python Answers

How to add a page redirect with Python Django?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *