Python Django Framework Quiz
A comprehensive 60-question quiz covering the Django web framework, from project structure and models to views, templates, and advanced configuration.
Question 1
In Django, what is the fundamental difference between a 'Project' and an 'App'?
Question 2
What is the primary purpose of the `manage.py` file created in every Django project?
Question 3
Which file in a Django app directory is used to configure app-specific settings, such as the app's name?
Question 4
Where does Django store the history of changes made to your database models?
Question 5
What is the role of `wsgi.py` in a Django project?
Question 6
You want to create a new app named 'blog' within your project. Which command do you run?
Question 7
How do you capture an integer parameter named 'id' from a URL path?
urlpatterns = [
path('post/____/', views.post_detail),
]
Question 8
What is the purpose of the `include()` function in `urls.py`?
from django.urls import path, include
urlpatterns = [
path('blog/', include('blog.urls')),
]
Question 9
Why is it recommended to name your URLs, e.g., `path(..., name='home')`?
Question 10
What is the difference between `path()` and `re_path()`?
Question 11
How do you namespace URLs for a specific app so that `post_detail` in 'blog' doesn't conflict with `post_detail` in 'news'?
Question 12
Which function is used in Python code (e.g., in views) to obtain the URL path from a view name?
Question 13
What is the first argument passed to every view function?
def my_view(____):
return HttpResponse("Hello")
Question 14
Which shortcut function loads a template, fills it with context, and returns an `HttpResponse` object?
Question 15
What does `get_object_or_404(MyModel, pk=1)` do?
Question 16
In a Class-Based View (CBV), which method handles GET requests?
Question 17
How do you return a JSON response from a view?
Question 18
What is the purpose of the `context` dictionary passed to `render`?
Question 19
In Django templates, what syntax is used to output the value of a variable?
Question 20
How do you enable template inheritance?
<!-- base.html -->
<html><body>{% block content %}{% endblock %}</body></html>
<!-- child.html -->
{% ____ 'base.html' %}
{% block content %}Hi{% endblock %}
Question 21
Which filter formats a date object?
{{ my_date|____:"Y-m-d" }}
Question 22
What does the `{% csrf_token %}` tag do?
Question 23
How do you load static files (like CSS) in a template?
{% ____ %}
<link rel="stylesheet" href="{% static 'style.css' %}">
Question 24
What happens if you try to access a dictionary key that doesn't exist in a template variable, e.g., `{{ my_dict.missing_key }}`?
Question 25
To define a database model, which class must you inherit from?
Question 26
Which field type is best suited for a long text entry (like a blog post body)?
Question 27
What does `on_delete=models.CASCADE` do in a ForeignKey?
Question 28
Where do you define model metadata like `verbose_name` or `ordering`?
class MyModel(models.Model):
name = models.CharField(max_length=100)
class ____:
ordering = ['name']
Question 29
Why should you define the `__str__` method in your model?
Question 30
Which command applies the pending migrations to the database?
Question 31
How do you register a model with the admin site?
# admin.py
from .models import Post
____(Post)
Question 32
Which `ModelAdmin` attribute controls the columns shown in the list view of objects?
Question 33
How do you add a sidebar filter to the admin list view?
Question 34
What command creates a user who can log in to the admin site?
Question 35
Can you group fields into sections on the admin edit page?
Question 36
How do you make a field read-only in the admin interface?
Question 37
What is Middleware in Django?
Question 38
In which order is middleware processed during a Request?
Question 39
Which middleware is responsible for associating a user with a request (i.e., `request.user`)?
Question 40
If you write a custom middleware class, which method is mandatory to implement?
Question 41
What happens if a middleware's `process_request` method returns an `HttpResponse`?
Question 42
Where do you activate middleware?
Question 43
Why must `DEBUG = True` never be used in production?
Question 44
What is the purpose of `ALLOWED_HOSTS`?
Question 45
Does the order of apps in `INSTALLED_APPS` matter?
Question 46
Which setting defines the database engine and credentials?
Question 47
What is `SECRET_KEY` used for?
Question 48
What does `ROOT_URLCONF` point to?
Question 49
What is the difference between `STATIC_URL` and `STATIC_ROOT`?
Question 50
Where does Django look for static files by default?
Question 51
What does the command `python manage.py collectstatic` do?
Question 52
Does Django serve static files in production automatically?
Question 53
What is the difference between Static files and Media files in Django terminology?
Question 54
How do you serve user-uploaded media files during development?
# urls.py
if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=____)
Question 55
What is the main advantage of using `ModelForm` over a standard `Form`?
Question 56
Which method checks if the form data is valid?
Question 57
Where is the sanitized data stored after calling `is_valid()`?
Question 58
How do you render a form in a template as a list of paragraphs?
<form method="post">
{{ form.____ }}
<button>Submit</button>
</form>
Question 59
What happens if you forget `{% csrf_token %}` in a POST form?
Question 60
How do you add custom validation for a specific field, e.g., 'email'?
