Unlock hundreds more features
Save your Quiz to the Dashboard
View and Export Results
Use AI to Create Quizzes and Analyse Results

Sign inSign in with Facebook
Sign inSign in with Google

Think You Can Ace This Django Quiz? Start Now!

Ready for a Django framework quiz? Dive in and challenge your skills!

Difficulty: Moderate
2-5mins
Learning OutcomesCheat Sheet
paper art style illustration of a Django quiz on teal background with stylized code sheets models views templates icons and progress bar

Use this Django quiz to check your skills with models, views, templates, and the ORM. You'll practice real web framework tasks and spot gaps fast, so you know what to review before an interview or exam. For more practice, try our Python quiz or a front-end quiz .

Which default port does 'python manage.py runserver' use if none is specified?
8080
5000
8000
80
By default, Django's development server listens on port 8000 when no port is provided. Port 8080 is commonly used for alternative HTTP testing, but Django does not use it by default. Port 80 is the standard HTTP port but requires elevated permissions. See for more.
In which file are Django settings defined by default?
settings.py
urls.py
config.py
manage.py
Django places all configuration options such as DATABASES, INSTALLED_APPS, and MIDDLEWARE in the settings.py file by default. There is no config.py in a standard project, and manage.py is a command-line utility. URL patterns reside in urls.py. See .
What is the purpose of INSTALLED_APPS in Django settings?
Define URL routing patterns
Enable middleware classes
List of applications active in the project
Configure template engines
INSTALLED_APPS tells Django which applications are enabled for the project and lets it include their models, admin interfaces, and migrations. Middleware is configured in MIDDLEWARE, templates in TEMPLATES, and URL routing in urls.py. More information at .
Which command creates migration files based on model changes?
python manage.py sqlmigrate
python manage.py migrate
python manage.py syncdb
python manage.py makemigrations
The makemigrations command inspects model changes and generates migration files. The migrate command applies them to the database. sqlmigrate shows the SQL for a migration, and syncdb is deprecated. See .
What file extension is commonly used for Django template files?
.tpl
.djhtml
.txt
.html
Django template files typically use the .html extension since they generate HTML pages. While you can configure other extensions, .djhtml and .tpl are uncommon, and .txt is used for plain text. For template settings see .
What is a QuerySet in Django?
A collection of database queries executed sequentially
A URL dispatcher
A template rendering engine
A list of model instances returned from a database query
A QuerySet represents a collection of objects from your database and can be filtered, ordered, and sliced. It's lazy, meaning it hits the database only when evaluated. QuerySets are not template engines or URL dispatchers. Read more at .
Which command applies migrations to the database?
python manage.py migrateall
python manage.py migrate
python manage.py syncdb
python manage.py makemigrations
The migrate command applies migration files to synchronize your database schema with your models. makemigrations only creates migration scripts. syncdb is removed in recent Django versions, and migrateall is not a valid command. More at .
How do you reference a URL by its name in Django templates?
{% link 'name' %}
{{ url('name') }}
{% path 'name' %}
{% url 'name' %}
The {% url %} template tag resolves a view name to its URL, allowing dynamic linking. There is no {% path %} or {% link %} tag, and {{ url() }} is invalid. See .
Which QuerySet method excludes records matching the lookup?
get()
only()
exclude()
filter()
The exclude() method returns a new QuerySet excluding items that match the given lookup. filter() returns matching items, only() limits fields, and get() retrieves a single object. See .
What does get_object_or_404 do?
Returns None if no object is found
Creates a new object if none exists
Logs an error and continues
Returns an object matching the query or raises Http404
get_object_or_404 attempts to retrieve an object by given parameters and raises Http404 if none is found. It does not return None or create objects, nor does it silently log errors. Documentation: .
In Django, what is a context?
The middleware processing order
HTTP request data
A list of URL patterns
A dictionary of data passed to a template for rendering
A context is a dictionary containing variables and data used by the template engine to produce the final HTML. It is not HTTP request data or URL patterns. Middleware order is unrelated. More info at .
Which template tag includes another template within a template?
{% include 'template.html' %}
{% embed 'template.html' %}
{% extends 'template.html' %}
{% import 'template.html' %}
The include tag pulls in another template's rendered content. extends creates a parent/child relationship for template inheritance. import and embed are not built-in tags. See .
What method checks form validity in Django forms?
is_valid()
clean()
full_clean()
validate()
The is_valid() method runs form validation and returns True if the form has no errors. The clean() methods perform field-specific cleaning, full_clean() is called internally, and validate() is not a form method. See .
Which field type is appropriate for text larger than 255 characters?
CharField
TextField
IntegerField
DateTimeField
TextField stores large amounts of text without a fixed max length. CharField requires a max_length parameter, and DateTimeField and IntegerField store dates and integers respectively. Documentation: .
How do you perform a case-insensitive exact match in a Django QuerySet?
filter(name__iexact='value')
filter(name__contains='value')
filter(name__exact='value')
filter(name__icontains='value')
The iexact lookup performs a case-insensitive match. exact is case-sensitive, icontains and contains perform substring matches. For more lookups see .
What is the difference between select_related and prefetch_related?
select_related follows foreign keys via SQL joins; prefetch_related does separate queries and joins in Python
prefetch_related uses SQL joins; select_related uses separate queries
They both perform joins but cache results differently
select_related is for ManyToMany; prefetch_related is for ForeignKey
select_related uses SQL JOINs for ForeignKey and OneToOne relationships to reduce queries. prefetch_related fetches related objects in separate queries and joins them in Python, ideal for ManyToMany and reverse ForeignKey. See .
What is the purpose of Django middleware?
To manage database transactions
To define URL patterns
To process requests and responses globally before and after views
To render templates
Middleware are hooks that process requests and responses globally, handling features like authentication, sessions, and content filtering. They do not define URLs, render templates, or directly manage transactions. Documentation: .
How do you define a custom user model in Django?
Set AUTH_USER_MODEL in settings and subclass AbstractUser or AbstractBaseUser
Subclass User in your views
Use a proxy model on the default User
Add extra fields to settings.py
Creating a custom user model involves subclassing AbstractUser or AbstractBaseUser and pointing AUTH_USER_MODEL to it in settings. Subclassing User in views or adding settings fields won't work. Proxy models don't allow new fields. See .
Which Django signal is sent before a model's save() method completes?
pre_delete
post_save
pre_save
pre_migrate
The pre_save signal is dispatched just before a model's save() method executes. post_save runs after saving, pre_delete before deletion, and pre_migrate before migrations. Details at .
What is a Generic Class-Based View for displaying a list of objects?
TemplateView
FormView
ListView
DetailView
ListView provides a generic interface to display a list of objects from a model. DetailView is for single-object detail, TemplateView is a simple template renderer, and FormView handles forms. See .
Which Django feature allows aggregation of QuerySet data, such as Count or Avg?
values()
annotate()
aggregate()
filter()
aggregate() returns a dictionary with aggregated values like Count or Avg over the whole QuerySet. annotate() adds calculated fields per object. values() changes output to dicts, and filter() selects records. See .
How do you enable file-based caching in Django?
Set CACHE_BACKEND in urls.py
Install django-redis and set REDIS_URL
Configure CACHES in settings with FileBasedCache backend and a LOCATION path
Add cache middleware to MIDDLEWARE only
To use file-based caching, you define the CACHES setting with 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache' and specify a LOCATION directory. Middleware alone won't configure the backend, and CACHE_BACKEND in urls.py is invalid. django-redis is for Redis caching. Reference: .
How do you create a custom template tag library in Django?
Add tag definitions to settings.py under TEMPLATE_TAGS
Write tags directly in views.py and import into templates
Place tag code in models.py and Django auto-discovers it
Create a templatetags package in an app, define a module with template.Library() and register tags
A custom template tag library requires a templatetags directory in your app with an __init__.py, then modules where you instantiate template.Library() and use @register.tag or @register.simple_tag. Settings or models.py approaches do not work. Documentation: .
How would you implement a custom database lookup for a Django model field?
Write raw SQL in a manager method without registration
Subclass django.db.models.Lookup and register it with Field.register_lookup()
Define a new database engine in settings.py
Override the filter() method in QuerySet to handle special syntax
Custom lookups require subclassing Lookup, defining lookup_name and as_sql(), then registering via Field.register_lookup(). Overriding filter() or writing raw SQL bypasses the lookup API, and changing database engines is unrelated. See .
0
{"name":"What command is used to start a new Django project?", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"What command is used to start a new Django project?, Which default port does 'python manage.py runserver' use if none is specified?, In which file are Django settings defined by default?","img":"https://www.quiz-maker.com/3012/images/ogquiz.png"}

Study Outcomes

  1. Understand Django Model Structures -

    Define core model components, field types, and relationships to build and manipulate database schemas effectively.

  2. Analyze View Functions and Class-Based Views -

    Differentiate between function-based and class-based views to handle HTTP requests and responses in a scalable way.

  3. Apply Template Tags and Filters -

    Use Django's templating language to render dynamic content, control flow, and format data within HTML pages.

  4. Identify URL Routing Patterns -

    Configure the URL dispatcher to map URLs to views, ensuring clean and maintainable application paths.

  5. Evaluate ORM Query Capabilities -

    Write and optimize database queries using Django's ORM to retrieve, filter, and aggregate data efficiently.

  6. Assess Overall Django Proficiency -

    Pinpoint your strengths and growth areas in Django development through targeted trivia questions and challenges.

Cheat Sheet

  1. Define Django Models and Migrations -

    Django models map Python classes to database tables using the official ORM. For example: class Book(models.Model): title = models.CharField(max_length=100), then run python manage.py makemigrations and python manage.py migrate to sync your schema. Mnemonic: "Models Mean Mapping."

  2. Master QuerySets and ORM Queries -

    The Django ORM lets you build database queries with methods like filter(), exclude() and annotate() instead of raw SQL. A common example is Author.objects.filter(name__icontains='smith'), and for complex lookups use Q objects. Remember "Query in Sets" to recall QuerySet basics.

  3. Choose Between Function-Based and Class-Based Views -

    Function-based views (FBVs) are simple Python functions, while class-based views (CBVs) offer built-in methods like get() and post() for reusability. For instance, ListView automates list display, reducing boilerplate. Think "FBV for Flex, CBV for Comfort."

  4. Configure URL Routing and Reverse Resolution -

    URLconf in Django uses path() or re_path() to map URLs to views, and assigns a name for reverse lookups. Example: path('posts//', views.detail, name='post-detail'), then use reverse('post-detail', args=[42]) to build URLs dynamically. A handy tip: namespacing avoids collisions in larger projects.

  5. Leverage Templates and Inheritance -

    Django's template language separates logic from presentation with tags like {% extends %} and {% block content %}. You can apply filters such as {{ user.username|upper }} to transform data in templates. Mnemonic: "Templates = HTML + Tiny Logic."

Powered by: Quiz Maker