0
0
Djangoframework~10 mins

CreateView for object creation 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 generic CreateView class from Django.

Django
from django.views.generic import [1]
Drag options to blanks, or click blank then click option'
ADetailView
BCreateView
CListView
DUpdateView
Attempts:
3 left
💡 Hint
Common Mistakes
Importing ListView or DetailView instead of CreateView.
Forgetting to import from django.views.generic.
2fill in blank
medium

Complete the code to specify the model for the CreateView.

Django
class BookCreateView(CreateView):
    model = [1]
Drag options to blanks, or click blank then click option'
ABook
BAuthor
CPublisher
DCategory
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different model name than intended.
Not specifying the model attribute.
3fill in blank
hard

Fix the error in the form_class assignment to use the correct form class.

Django
class BookCreateView(CreateView):
    form_class = [1]
Drag options to blanks, or click blank then click option'
ACategoryForm
BAuthorForm
CPublisherForm
DBookForm
Attempts:
3 left
💡 Hint
Common Mistakes
Using a form class for a different model.
Not importing the form class.
4fill in blank
hard

Fill both blanks to set the template name and success URL for the CreateView.

Django
class BookCreateView(CreateView):
    template_name = '[1]'
    success_url = '[2]'
Drag options to blanks, or click blank then click option'
Abooks/book_form.html
B/books/
Cauthors/author_form.html
D/authors/
Attempts:
3 left
💡 Hint
Common Mistakes
Using template or URL for a different model.
Forgetting to add trailing slashes in URLs.
5fill in blank
hard

Fill all three blanks to complete the CreateView with model, fields, and success URL.

Django
class AuthorCreateView(CreateView):
    model = [1]
    fields = ['first_name', 'last_name']
    success_url = '[2]'

# URL pattern
path('authors/add/', [3].as_view(), name='author-add')
Drag options to blanks, or click blank then click option'
AAuthor
B/authors/
CAuthorCreateView
DBook
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up model and view class names.
Using wrong URL paths or names.