Redirect with parameters in Django

In this tutorial, we will discuss how to redirect with parameters in Django.

To know more about Redirect click on the given link –¬†Redirect in Django

Redirect With Parameters

First, start your project and create an app inside your project.

After this just write the below code in views.py:-

from django.shortcuts import redirect

def codespeedy(request):
    return redirect("https://www.codespeedy.com/")
def google(request):
    return redirect("https://www.google.com/")

Then, make changes in urls.py to redirect to another page.

from django.urls import path
from django.contrib import admin
from . import views

urlpatterns = [
    path('admin/', admin.site.urls),
    path('codespeedy',views.codespeedy,name="codespeedy"),
    path('google',views.google,name="google"),
]

Output

To redirect to the official site of CodeSpeedy just run the command python manage.py runserverand then navigate to http://127.0.0.1:8000/codespeedy.

To redirect to the official site of google navigate to http://127.0.0.1:8000/google  the google site will open.

Leave a Reply

Your email address will not be published.