Tasos Sangiotis

Django: Redirecting from urls.py

I made some changes and slashed a page.

Now it is possible some users have the page bookmarked or on an email and I wanted this to work but to not retain the url.

At the same time I dind’t want to create a view just for that.

There is a better way:

from django.views.generic import RedirectView

...

urlpatterns = [
    ...
    path(
        "measurementpoint/<uuid:pk>/history/",
        RedirectView.as_view(pattern_name="measurementpoint", permanent=True),
    ),
    ...
]

Comment details and information

To make a comment, please send an e-mail using the button below. Your e-mail address won't be shared and will be deleted from my records after the comment is published. If you don't want your real name to be credited alongside your comment, please specify the name you would like to use. If you would like your name to link to a specific URL, please share that as well. Thank you.