Redirects with redirect function
📖 Scenario: You are building a simple Django web app that needs to send users from one page to another automatically.For example, after a user visits a welcome page, you want to send them to the homepage.
🎯 Goal: Learn how to use Django's redirect function to send users from one view to another.You will create a view that redirects to another URL.
📋 What You'll Learn
Create a Django view function named
welcome_view that redirects to the URL path /home/ using the redirect function.Import the
redirect function from django.shortcuts.Create a second view function named
home_view that returns a simple HTTP response with the text "Welcome Home!".Add URL patterns for
/welcome/ and /home/ paths pointing to welcome_view and home_view respectively.💡 Why This Matters
🌍 Real World
Redirects are common in web apps to guide users after actions like login, logout, or form submission.
💼 Career
Understanding redirects is essential for backend web developers working with Django to control user navigation flow.
Progress0 / 4 steps