0
0
Djangoframework~10 mins

Redirects with redirect function in Django - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the redirect function from Django shortcuts.

Django
from django.shortcuts import [1]
Drag options to blanks, or click blank then click option'
Aredirect
Brender
Cget_object_or_404
DHttpResponse
Attempts:
3 left
💡 Hint
Common Mistakes
Importing render instead of redirect
Trying to import redirect from django.http
Forgetting to import redirect at all
2fill in blank
medium

Complete the code to redirect the user to the URL named 'home'.

Django
return [1]('home')
Drag options to blanks, or click blank then click option'
Arender
Bredirect
CHttpResponseRedirect
Dreverse
Attempts:
3 left
💡 Hint
Common Mistakes
Using render instead of redirect
Using reverse without redirect
Returning a string instead of a redirect
3fill in blank
hard

Fix the error in the redirect call to use the correct function.

Django
return [1]('/dashboard/')
Drag options to blanks, or click blank then click option'
Arender
BHttpResponse
Credirect
Dget_object_or_404
Attempts:
3 left
💡 Hint
Common Mistakes
Using HttpResponse instead of redirect
Using render instead of redirect
Not importing redirect before use
4fill in blank
hard

Fill both blanks to redirect to a URL named 'profile' with an argument user_id.

Django
from django.urls import [1]
return redirect([2]('profile', args=[user_id]))
Drag options to blanks, or click blank then click option'
Areverse
Brender
CHttpResponseRedirect
Dget_object_or_404
Attempts:
3 left
💡 Hint
Common Mistakes
Using render instead of reverse
Using HttpResponseRedirect instead of reverse
Not passing args as a list
5fill in blank
hard

Fill all three blanks to redirect to a named URL 'article-detail' with keyword argument 'pk' equal to article.id.

Django
from django.urls import [1]
url = [2]('article-detail', [3]={'pk': article.id})
return redirect(url)
Drag options to blanks, or click blank then click option'
Areverse
Brender
Ckwargs
Dargs
Attempts:
3 left
💡 Hint
Common Mistakes
Using args instead of kwargs for keyword arguments
Using render instead of reverse
Not importing reverse from django.urls