Question bank

Pick an answer to see if you're right — with an explanation.

DjangoEasy
Which command creates migration files?
amigrate
bcreatemigrations
csyncdb
dmakemigrations
DjangoEasy
Which form method must return `True` before you use `cleaned_data`?
aform.save()
bform.clean()
cform.is_valid()
dform.has_changed()
DjangoEasy
Django's architecture is often called…
aMTV
bMVC
cMVVM
dMVP
DjangoEasy
Which decorator redirects anonymous users to the login page?
a@login_required
b@csrf_protect
c@require_POST
d@never_cache
DjangoEasy
Which protects forms against CSRF?
a{% secure %}
b@login_required
c{% csrf_token %}
dSECRET_KEY
DjangoEasy
Which generic view is designed to show a single object?
aListView
bTemplateView
cRedirectView
dDetailView
DjangoEasy
Which setting must be False in production?
aUSE_TZ
bDEBUG
cAPPEND_SLASH
dUSE_I18N
DjangoEasy
Which default permission codename does Django create for editing a `Product` in app `shop`?
ashop.edit_product
bshop.change_product
cshop.update_product
dshop.modify_product
DjangoMedium
To avoid N+1 queries on a ForeignKey use…
aselect_related
bprefetch_related
conly()
dvalues()
DjangoMedium
Why redirect after a successful POST instead of rendering a template?
aRedirects are faster
bTemplates cannot be rendered after POST
cIt prevents the form being resubmitted when the user refreshes
dDjango requires it for CSRF
DjangoMedium
For the URL /posts/7/, what does the view receive?
path('posts/<int:pk>/', views.post_detail, name='post-detail')
aThe positional string '7'
bNothing; pk must be read from request.GET
cThe keyword argument pk=7 as an int
dThe whole path as one string
DjangoMedium
What is wrong with this view?
class OrderCreate(CreateView, LoginRequiredMixin):
    model = Order
    fields = ['items']
aMixins cannot be used with CreateView
bLoginRequiredMixin must come before CreateView to take effect
c`fields` must be a tuple
dCreateView requires a success_url
DjangoMedium
Which setting does `collectstatic` copy files into for production?
aSTATICFILES_DIRS
bMEDIA_ROOT
cSTATIC_URL
dSTATIC_ROOT
DjangoMedium
Which call returns a single dictionary like `{'revenue': ...}` for the whole queryset?
aOrder.objects.aggregate(revenue=Sum('total'))
bOrder.objects.annotate(revenue=Sum('total'))
cOrder.objects.values('total')
dOrder.objects.only('total')
DjangoMedium
Which call raises `Product.DoesNotExist` when nothing matches?
aProduct.objects.filter(pk=5)
bProduct.objects.get(pk=5)
cProduct.objects.all()
dProduct.objects.exclude(pk=5)