About Redirecting to Another Page

You can redirect a URL to another page using one of the following:

1
2
3
4
5
6
from django.urls import path
from django.shortcuts import redirect

urlpatterns = [
    path("", lambda request: redirect("dashboard")),
]

or

1
2
3
4
5
6
from django.urls import path, reverse_lazy
from django.views.generic import RedirectView

urlpatterns = [
    path("", RedirectView.as_view(url=reverse_lazy("dashboard"))),
]

Tips and Tricks Programming Django 4.2 Django 3.2 Django 2.2