0
0
Djangoframework~10 mins

TemplateView for simple pages 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 correct class for rendering a simple template page.

Django
from django.views.generic import [1]
Drag options to blanks, or click blank then click option'
AListView
BTemplateView
CDetailView
DFormView
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing ListView or DetailView which are for models.
Using FormView which is for forms.
2fill in blank
medium

Complete the code to define a simple TemplateView class that uses 'about.html' as its template.

Django
class AboutPageView([1]):
    template_name = 'about.html'
Drag options to blanks, or click blank then click option'
ATemplateView
BListView
CDetailView
DFormView
Attempts:
3 left
💡 Hint
Common Mistakes
Using ListView or DetailView which require models.
Forgetting to set the template_name attribute.
3fill in blank
hard

Fix the error in the URL pattern to correctly use the AboutPageView class.

Django
from django.urls import path
from .views import AboutPageView

urlpatterns = [
    path('about/', [1].as_view(), name='about'),
]
Drag options to blanks, or click blank then click option'
AAboutPageView.as_view
BAboutPageView()
CAboutPageView.as_view()
DAboutPageView
Attempts:
3 left
💡 Hint
Common Mistakes
Using AboutPageView without calling as_view().
Calling AboutPageView() which creates an instance, not a view function.
4fill in blank
hard

Fill both blanks to add extra context data to the template in a TemplateView subclass.

Django
class ContactPageView(TemplateView):
    template_name = 'contact.html'

    def get_context_data(self, **kwargs):
        context = super().[1](**kwargs)
        context['email'] = [2]
        return context
Drag options to blanks, or click blank then click option'
Aget_context_data
Bget_context
C'contact@example.com'
D'email@example.com'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong method name like get_context.
Forgetting to call super().get_context_data.
Not returning the context dictionary.
5fill in blank
hard

Fill all three blanks to create a URL pattern for a TemplateView that uses a custom name and template.

Django
from django.urls import path
from django.views.generic import [1]

urlpatterns = [
    path('help/', [2].as_view(template_name=[3]), name='help'),
]
Drag options to blanks, or click blank then click option'
ATemplateView
BHelpPageView
C'help.html'
D'help_page.html'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a view class that is not imported.
Passing template_name without quotes.
Using a non-existent view class like HelpPageView without defining it.