Tasos Sangiotis profile picture

Tasos Sangiotis

Django: Redirecting from urls.py

I made some changes and slashed a page on Mechbase.

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 did'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),
    ),
    ...
]