Challenge - 5 Problems
Redirect Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this Django view return?
Consider this Django view function using the
redirect function. What will the user see after accessing this view?Django
from django.shortcuts import redirect def my_view(request): return redirect('home')
Attempts:
2 left
💡 Hint
Think about what the redirect function does with a string argument.
✗ Incorrect
The redirect function takes a URL name and sends the user to that URL. It does not render text or raise an error if the URL name exists.
📝 Syntax
intermediate2:00remaining
Which option correctly uses the redirect function to send to a URL path?
You want to redirect the user to the URL path '/dashboard/'. Which code snippet correctly does this?
Attempts:
2 left
💡 Hint
The redirect function can take a URL path as a string directly.
✗ Incorrect
Passing '/dashboard/' as a string to redirect sends the user to that exact URL path. The other options either misuse parameters or treat the string as a URL name.
🔧 Debug
advanced2:00remaining
Why does this redirect cause an error?
This Django view tries to redirect using a variable but causes an error. Why?
def my_view(request):
url_name = home
return redirect(url_name)Django
def my_view(request): url_name = home return redirect(url_name)
Attempts:
2 left
💡 Hint
Look at how the variable url_name is assigned.
✗ Incorrect
The code assigns url_name = home without quotes, so Python looks for a variable named home which is not defined, causing a NameError.
❓ state_output
advanced2:00remaining
What is the HTTP status code of this redirect response?
Given this Django view, what HTTP status code will the redirect response have?
from django.shortcuts import redirect
def my_view(request):
return redirect('login')Django
from django.shortcuts import redirect def my_view(request): return redirect('login')
Attempts:
2 left
💡 Hint
By default, redirect sends a temporary redirect status.
✗ Incorrect
Django's redirect function returns an HttpResponseRedirect with status code 302 by default, indicating a temporary redirect.
🧠 Conceptual
expert3:00remaining
Which redirect usage correctly passes URL parameters?
You want to redirect to a URL named 'profile' that requires a username parameter. Which option correctly passes the parameter using Django's redirect function?
Attempts:
2 left
💡 Hint
Use keyword arguments to pass URL parameters to redirect.
✗ Incorrect
The redirect function accepts the URL name and keyword arguments for URL parameters. Option B correctly uses this pattern.