Recall & Review
beginner
What does the
redirect() function do in Django?The
redirect() function sends the user to a different URL or view. It tells the browser to load a new page instead of the current one.Click to reveal answer
beginner
How do you use
redirect() to send a user to a URL named 'home'?You use
redirect('home'). This tells Django to find the URL linked to the name 'home' and send the user there.Click to reveal answer
intermediate
Can
redirect() accept a model instance as an argument? What happens?Yes. If you pass a model instance, Django will call its
get_absolute_url() method and redirect to that URL.Click to reveal answer
intermediate
What HTTP status code does
redirect() send by default?It sends a 302 status code, which means 'Found' and tells the browser to temporarily redirect to another URL.
Click to reveal answer
beginner
How can you redirect to an absolute URL using
redirect()?You can pass the full URL string to
redirect(), like redirect('https://example.com'), and Django will send the user there.Click to reveal answer
What argument types can the
redirect() function accept in Django?✗ Incorrect
The
redirect() function can accept a URL name, an absolute URL string, or a model instance with a get_absolute_url() method.What HTTP status code does Django's
redirect() send by default?✗ Incorrect
By default,
redirect() sends a 302 status code, indicating a temporary redirect.Which Django function would you use to send a user to a different page?
✗ Incorrect
redirect() is used to send users to a different URL or view.If you pass a model instance to
redirect(), what method does Django call to get the URL?✗ Incorrect
Django calls the model's
get_absolute_url() method to find the URL to redirect to.How do you redirect to a named URL pattern called 'dashboard'?
✗ Incorrect
You can pass the URL name directly to
redirect() like redirect('dashboard').Explain how the
redirect() function works in Django and when you would use it.Think about how websites send you to new pages after actions.
You got /4 concepts.
Describe how Django handles a model instance passed to
redirect().Models can tell Django their own URL.
You got /2 concepts.