Question bank
Pick an answer to see if you're right — with an explanation.
All topicsPythonSQL / MySQLData ScienceNumPyPandasMatplotlibMachine LearningDeep LearningArtificial IntelligenceLarge Language ModelsDjangoAPIsGit & GitHubPower BIExcelStatistics
DjangoEasy
Which command creates migration files?
amigrate
bcreatemigrations
csyncdb
dmakemigrations
Explanation: makemigrations generates files; migrate applies them.
DjangoEasy
Which form method must return `True` before you use `cleaned_data`?
aform.save()
bform.clean()
cform.is_valid()
dform.has_changed()
Explanation: `is_valid()` runs all validation and populates `cleaned_data`.
DjangoEasy
Django's architecture is often called…
aMTV
bMVC
cMVVM
dMVP
Explanation: Model-Template-View.
DjangoEasy
Which decorator redirects anonymous users to the login page?
a@login_required
b@csrf_protect
c@require_POST
d@never_cache
Explanation: `@login_required` sends unauthenticated users to `LOGIN_URL`.
DjangoEasy
Which protects forms against CSRF?
a{% secure %}
b@login_required
c{% csrf_token %}
dSECRET_KEY
Explanation: The csrf_token tag adds a hidden token.
DjangoEasy
Which generic view is designed to show a single object?
aListView
bTemplateView
cRedirectView
dDetailView
Explanation: DetailView fetches one object by pk or slug and renders it.
DjangoEasy
Which setting must be False in production?
aUSE_TZ
bDEBUG
cAPPEND_SLASH
dUSE_I18N
Explanation: DEBUG=True leaks sensitive information.
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
Explanation: Django auto-creates add_, change_, delete_ and view_ permissions for each model.
DjangoMedium
To avoid N+1 queries on a ForeignKey use…
aselect_related
bprefetch_related
conly()
dvalues()
Explanation: select_related does a SQL JOIN for FK/OneToOne.
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
Explanation: The Post/Redirect/Get pattern leaves the browser on a GET page, so refresh doesn't repeat the POST.
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
Explanation: The `int` converter matches digits and passes the captured value to the view as the integer keyword argument `pk`.
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
Explanation: Python's method resolution order checks classes left to right, so access mixins must be listed first.
DjangoMedium
Which setting does `collectstatic` copy files into for production?
aSTATICFILES_DIRS
bMEDIA_ROOT
cSTATIC_URL
dSTATIC_ROOT
Explanation: collectstatic gathers app and project static files into STATIC_ROOT, the single directory the web server serves.
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')
Explanation: `aggregate()` summarises the whole queryset; `annotate()` adds a value per row.
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)
Explanation: `get()` returns exactly one object and raises DoesNotExist or MultipleObjectsReturned; `filter()` simply returns an empty queryset.