0
0
Djangoframework~5 mins

Redirects with redirect function in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AURL name, absolute URL string, or model instance
BOnly absolute URL strings
COnly URL names
DOnly model instances
What HTTP status code does Django's redirect() send by default?
A200
B301
C302
D404
Which Django function would you use to send a user to a different page?
Aredirect()
Bget_object_or_404()
Crender()
Dreverse()
If you pass a model instance to redirect(), what method does Django call to get the URL?
Aget_url()
Bget_absolute_url()
Cget_redirect_url()
Dget_path()
How do you redirect to a named URL pattern called 'dashboard'?
Aredirect('/dashboard')
Bredirect(url='dashboard')
Credirect(reverse('dashboard'))
Dredirect('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.