0
0
Djangoframework~10 mins

Login view and template 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 Django login view.

Django
from django.contrib.auth.views import [1]
Drag options to blanks, or click blank then click option'
ALoginView
BSignupView
CPasswordResetView
DLogoutView
Attempts:
3 left
💡 Hint
Common Mistakes
Importing LogoutView instead of LoginView
Using SignupView which is not built-in
Confusing PasswordResetView with LoginView
2fill in blank
medium

Complete the code to define a URL pattern for the login view.

Django
path('login/', [1].as_view(), name='login')
Drag options to blanks, or click blank then click option'
ASignupView
BLogoutView
CLoginView
DPasswordResetView
Attempts:
3 left
💡 Hint
Common Mistakes
Using LogoutView instead of LoginView
Forgetting to call as_view()
Using a view not related to login
3fill in blank
hard

Fix the error in the login template to correctly display the username input field.

Django
<input type="text" name="[1]" placeholder="Username">
Drag options to blanks, or click blank then click option'
Ausername
Bemail
Cuser
Dlogin
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'email' instead of 'username' without custom backend
Using 'user' which is not recognized
Using 'login' which is not a valid field name
4fill in blank
hard

Fill both blanks to complete the login template form with CSRF token and password input.

Django
<form method="post">
  {% csrf_token %}
  <input type="text" name="username" placeholder="Username">
  <input type="[1]" name="password" placeholder="Password">
  <button type="[2]">Log In</button>
</form>
Drag options to blanks, or click blank then click option'
Asubmit
Bpassword
Cbutton
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Using input type 'text' for password
Using button type 'button' which does not submit the form
5fill in blank
hard

Fill all three blanks to customize the login view with a template and redirect URL.

Django
class CustomLoginView(LoginView):
    template_name = '[1]'
    redirect_authenticated_user = [2]
    next_page = '[3]'
Drag options to blanks, or click blank then click option'
Alogin.html
BTrue
C/dashboard/
DFalse
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect template file name
Setting redirect_authenticated_user to False
Leaving next_page empty or incorrect