0
0
Djangoframework~10 mins

Registration with UserCreationForm 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 UserCreationForm from Django's auth forms.

Django
from django.contrib.auth.forms import [1]
Drag options to blanks, or click blank then click option'
AAuthenticationForm
BUserCreationForm
CUserChangeForm
DPasswordChangeForm
Attempts:
3 left
💡 Hint
Common Mistakes
Importing AuthenticationForm instead of UserCreationForm
Using UserChangeForm which is for editing users
Forgetting to import from django.contrib.auth.forms
2fill in blank
medium

Complete the view function to instantiate the UserCreationForm with POST data.

Django
form = [1](request.POST or None)
Drag options to blanks, or click blank then click option'
AUserChangeForm
BAuthenticationForm
CUserCreationForm
DPasswordResetForm
Attempts:
3 left
💡 Hint
Common Mistakes
Using AuthenticationForm which is for login
Not passing request.POST to the form
Passing request.GET instead of request.POST
3fill in blank
hard

Fix the error in the form validation check in the view.

Django
if form.[1]():
Drag options to blanks, or click blank then click option'
Ais_valid
Bvalidate
Cisvalid
Dcheck_valid
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'validate' which is not a form method
Missing parentheses after 'is_valid'
Using 'isvalid' without underscore
4fill in blank
hard

Fill both blanks to save the new user and redirect after successful registration.

Django
if form.is_valid():
    user = form.[1]()
    return redirect('[2]')
Drag options to blanks, or click blank then click option'
Asave
Blogin
Chome
Dlogout
Attempts:
3 left
💡 Hint
Common Mistakes
Calling 'login' instead of 'save' on the form
Redirecting to 'logout' which logs the user out
Forgetting to save the form before redirect
5fill in blank
hard

Fill all three blanks to complete the registration view with form rendering and POST handling.

Django
def register(request):
    if request.method == '[1]':
        form = UserCreationForm(request.POST)
        if form.is_valid():
            form.[2]()
            return redirect('[3]')
    else:
        form = UserCreationForm()
    return render(request, 'register.html', {'form': form})
Drag options to blanks, or click blank then click option'
APOST
Bsave
Chome
DGET
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'GET' instead of 'POST' to process form data
Not calling 'save()' before redirect
Redirecting to a wrong URL name