Unit 3: Templates, Debugging and Testing - Practice Quiz

INT253 — Web Development In Python Using Django 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the main purpose of a Django template?

Introduction to Templates in Django Easy
A. To present data as HTML
B. To configure URL routes
C. To define database tables
D. To start the development server

2 Which type of content is most commonly stored in a Django template?

Introduction to Templates in Django Easy
A. HTML with template syntax
B. JSON with server settings
C. SQL with database queries
D. Python with model classes

3 Which file extension is commonly used for Django template files?

Creating Templates Easy
A. .html
B. .py
C. .sql
D. .ini

4 Which directory name is commonly used to store Django template files?

Creating Templates Easy
A. migrations
B. templates
C. media
D. static

5 Which syntax displays a value in Django Template Language?

Working with Django Template Language (DTL) Easy
A. {# name #}
B. [[ name ]]
C. {{ name }}
D. {% name %}

6 Which symbol is used to apply a filter to a Django template variable?

Working with Django Template Language (DTL) Easy
A. |
B. @
C. #
D. &

7 Which delimiters are used for Django template tags?

Using template tags Easy
A. <% and %>
B. {{ and }}
C. {# and #}
D. {% and %}

8 Which Django template tag helps protect a form from cross-site request forgery?

Using template tags Easy
A. {% csrf_token %}
B. {% comment %}
C. {% include %}
D. {% static %}

9 How is a template variable named username displayed?

Django variables Easy
A. < username >
B. {# username #}
C. {% username %}
D. {{ username }}

10 How can a template access the name attribute of a variable called student?

Django variables Easy
A. {{ student->name }}
B. {{ student.name }}
C. {{ student:name }}
D. {{ student/name }}

11 Which tag correctly starts a loop over a list named products?

for loop and if-else statements Easy
A. {% while product in products %}
B. {% loop product from products %}
C. {% for product in products %}
D. {% each product of products %}

12 Which tag closes a Django template if statement?

for loop and if-else statements Easy
A. {% closeif %}
B. {% stopif %}
C. {% endif %}
D. {% finishif %}

13 What is normally passed from a Django view to a template to provide dynamic values?

Dynamic Templates in Django Easy
A. A settings module
B. A migration file
C. A URL pattern
D. A context dictionary

14 Which Django shortcut commonly combines a template with context data and returns a response?

Dynamic Templates in Django Easy
A. redirect()
B. render()
C. include()
D. reverse()

15 Which tag tells a child template to inherit from a parent template?

Working with Template inheritance Easy
A. {% extends "base.html" %}
B. {% require "base.html" %}
C. {% import "base.html" %}
D. {% include "base.html" %}

16 Which tag defines an area that child templates can replace?

Working with Template inheritance Easy
A. {% area content %}
B. {% block content %}
C. {% section content %}
D. {% region content %}

17 Which Django setting displays detailed error pages during development when enabled?

Debugging Django applications Easy
A. DEBUG
B. LANGUAGE_CODE
C. STATIC_URL
D. ALLOWED_HOSTS

18 Why should DEBUG normally be set to False in production?

Debugging Django applications Easy
A. To enable the Django administration site
B. To allow templates to inherit correctly
C. To make database tables update automatically
D. To prevent sensitive error details from appearing

19 Which command runs the test suite of a Django project?

Testing in Django Easy
A. python manage.py migrate
B. python manage.py collectstatic
C. python manage.py test
D. python manage.py startapp

20 Which Django class is commonly extended when writing test cases?

Testing in Django Easy
A. django.views.TestCase
B. django.test.TestCase
C. django.forms.TestCase
D. django.urls.TestCase

21 A view retrieves product data from the database. Which approach best follows Django's separation of concerns?

Introduction to Templates in Django Medium
A. Pass product data from the view to a template
B. Write database queries directly inside the template
C. Format the complete HTML inside the model
D. Store the rendered HTML in the URL configuration

22 Which statement correctly renders shop/product_list.html with a variable named products?

Introduction to Templates in Django Medium
A. return HttpResponse(request, "shop/product_list.html", products)
B. return render("shop/product_list.html", request, products)
C. return redirect(request, "shop/product_list.html", {"products": products})
D. return render(request, "shop/product_list.html", {"products": products})

23 Two installed applications both contain a template named details.html. Which directory structure best prevents template-name collisions?

Creating Templates Medium
A. templates/details/app1.html
B. app1/details/templates.html
C. app1/templates/common/details.html
D. app1/templates/app1/details.html

24 A template is stored at project_templates/dashboard.html, outside all Django applications. Which setting is normally updated so Django can locate it?

Creating Templates Medium
A. MIDDLEWARE["TEMPLATES"]
B. TEMPLATES[0]["DIRS"]
C. TEMPLATES[0]["OPTIONS"]
D. INSTALLED_APPS["DIRS"]

25 A context variable title contains django testing. Which expression displays it as Django Testing?

Working with Django Template Language (DTL) Medium
A. {{ title|upper }}
B. {{ title|title }}
C. {% title title %}
D. {{ title.capitalize }}

26 The variable comment contains the text <strong>Great</strong> submitted by a user. What does {{ comment }} normally display when autoescaping is enabled?

Working with Django Template Language (DTL) Medium
A. The value is removed because Django permanently strips every HTML element before rendering the response
B. The text appears in bold
C. The variable causes a template error
D. The HTML tags appear as text

27 Given a URL pattern named product-detail that requires an integer pk, which template tag correctly generates the URL for product.pk?

Using template tags Medium
A. {% link 'product-detail' product.pk %}
B. {% url product.pk as 'product-detail' %}
C. {{ url 'product-detail' product.pk }}
D. {% url 'product-detail' product.pk %}

28 A form submits data with method="post" to a Django view protected by CSRF middleware. What should be placed inside the <form> element?

Using template tags Medium
A. {{ csrf_token() }}
B. {% csrf_protect request %}
C. {% load csrf %}
D. {% csrf_token %}

29 The view passes {"student": {"name": "Asha"}} as context. Which template expression displays Asha?

Django variables Medium
A. {% student.name %}
B. {{ context.student.name }}
C. {{ student["name"] }}
D. {{ student.name }}

30 A template contains Welcome, {{ username }}!, but username is absent from the context. What normally happens with Django's default template behavior?

Django variables Medium
A. Django automatically reads username from the authenticated user and displays it without requiring context
B. The template displays the word None
C. The template raises KeyError immediately
D. The variable renders as an empty string

31 Which DTL structure displays No products found only when the products collection is empty?

for loop and if-else statements Medium
A. {% for p in products %}{{ p.name }}{% else %}No products found{% endfor %}
B. {% for p in products %}{{ p.name }}{% empty %}No products found{% endfor %}
C. {% loop p in products %}{{ p.name }}{% empty %}No products found{% endloop %}
D. {% if products %}No products found{% else %}{{ products }}{% endif %}

32 Inside a loop over orders, which condition adds a separator after every order except the last one?

for loop and if-else statements Medium
A. {% if orders.last != order %}<hr>{% endif %}
B. {% if not forloop.last %}<hr>{% endif %}
C. {% if forloop.counter == 0 %}<hr>{% endif %}
D. {% if forloop.first %}<hr>{% endif %}

33 A view must display a different greeting based on a name captured from the URL. Which implementation is most appropriate?

Dynamic Templates in Django Medium
A. Pass the captured name to the template context
B. Place the URL resolver inside the template so it can rerun the view and retrieve the captured name
C. Create a separate template for every possible name
D. Modify settings.py whenever the name changes

34 A view passes {"is_member": True} to a template. Which code dynamically shows Member Dashboard for members and Guest Dashboard otherwise?

Dynamic Templates in Django Medium
A. {% if is_member %}Member Dashboard{% else %}Guest Dashboard{% endif %}
B. {% for is_member %}Member Dashboard{% empty %}Guest Dashboard{% endfor %}
C. {{ if is_member }}Member Dashboard{{ else }}Guest Dashboard{{ endif }}
D. {% if is_member == "True" %}Member Dashboard{% otherwise %}Guest Dashboard{% endif %}

35 A child template extends base.html and needs to replace its content block. Which structure is correct?

Working with Template inheritance Medium
A. {% inherit 'base.html' %}{% override content %}Page content{% endoverride %}
B. {% include 'base.html' %}{% content %}Page content{% endcontent %}
C. {% block 'base.html' %}{% extends content %}Page content{% endblock %}
D. {% extends 'base.html' %}{% block content %}Page content{% endblock %}

36 A child template overrides the sidebar block but must retain the parent's sidebar before adding new links. What should the child block use?

Working with Template inheritance Medium
A. {{ parent.sidebar }}
B. {{ block.super }}
C. {% extends sidebar.parent %}
D. {% include block.super %}

37 A page raises an exception during local development, but the browser only shows a generic server error. Which configuration is most directly relevant for displaying Django's detailed debug page?

Debugging Django applications Medium
A. Set ALLOWED_HOSTS = [] in every environment
B. Set DEBUG = True on the production server and expose the technical traceback publicly for easier diagnosis
C. Remove all middleware from the project settings
D. Set DEBUG = True in the development settings

38 A template raises TemplateDoesNotExist: blog/post_list.html. The file is actually stored as blog/templates/blog/posts_list.html. What is the most direct fix?

Debugging Django applications Medium
A. Add .django to the template filename
B. Move the template into the migrations directory
C. Render templates/blog/posts_list.html instead
D. Render blog/posts_list.html instead

39 Which test correctly verifies that the URL named home returns HTTP status code ?

Testing in Django Medium
A. response = self.client.get(reverse('home')); self.assertEqual(response.status_code, 200)
B. response = reverse(self.client.get('home')); self.assertTrue(response.status_code)
C. response = self.client.post(reverse('home')); self.assertEqual(response.template, 200)
D. response = self.client.get('home'); self.assertEqual(response, HttpResponse.status_ok)

40 A test must confirm that requesting a product-list page uses shop/product_list.html. Which assertion is designed for this purpose?

Testing in Django Medium
A. self.assertRedirects(response, 'shop/product_list.html')
B. self.assertTemplateUsed(response, 'shop/product_list.html')
C. self.assertEqual(response.url, 'shop/product_list.html')
D. self.assertContains(response, 'shop/product_list.html')

41 A project configures two Django template engines with aliases public and admin. Both engines can resolve dashboard.html. A view must render the template from the admin engine regardless of template search order. Which call provides that guarantee?

Introduction to Templates in Django Hard
A. render(request, "admin:dashboard.html", context)
B. render(request, "dashboard.html", context, using="admin")
C. render_to_response("dashboard.html", context, alias="admin")
D. render(request, "dashboard.html", context, engine="admin")

42 A project uses the Django template backend with DIRS = [BASE_DIR / "templates"], APP_DIRS = True, and INSTALLED_APPS = ["shop", "accounts"]. The same receipt.html exists in the project template directory and in both applications' templates directories. What does get_template("receipt.html") load?

Creating Templates Hard
A. The file under BASE_DIR/templates
B. The file under shop/templates
C. The file under accounts/templates
D. A TemplateDoesNotExist ambiguity error

43 Given the context {"data": {"items": "dictionary value"}}, what does {{ data.items }} render in a Django template?

Working with Django Template Language (DTL) Hard
A. dictionary value
B. The dictionary's item pairs
C. An empty string
D. A template syntax error

44 The context contains an object report whose zero-argument method summary() returns "Ready". What normally happens when the template evaluates {{ report.summary }}?

Django variables Hard
A. DTL treats all methods as unavailable
B. DTL requires {{ report.summary() }}
C. DTL calls the method and renders Ready
D. DTL renders the bound method representation

45 A context variable is missing, and the engine uses its default string_if_invalid value. Consider {% if missing %}A{% else %}B{% endif %}|{{ missing|default:"C" }}. What is rendered?

Django variables Hard
A. B|C
B. A|
C. A|C
D. B|

46 Suppose {% url "reports:detail" missing_id as report_url %} cannot reverse the URL because missing_id is invalid. What is the key effect of assigning the result with as report_url?

Using template tags Hard
A. report_url receives the unresolved URL pattern text
B. report_url becomes empty instead of raising NoReverseMatch
C. report_url receives the current request path
D. report_url becomes None and the exception is logged

47 A parent context has theme="dark" and user. What variables are intentionally available to row.html when it is rendered by {% include "row.html" with theme="light" only %}?

Using template tags Hard
A. All parent variables except user
B. Only theme, with the value light
C. Only theme, with the value dark
D. theme as light plus user

48 An outer loop iterates over two categories, and each category has three products. Inside the inner loop, which expression renders the current category's one-based position rather than the product's position?

for loop and if-else statements Hard
A. {{ forloop.parent.counter }}
B. {{ parentloop.counter }}
C. {{ forloop.counter0 }}
D. {{ forloop.parentloop.counter }}

49 For a=True, b=False, and c=False, which branch is selected by {% if a or b and c %}X{% else %}Y{% endif %}?

for loop and if-else statements Hard
A. X, because and is evaluated before or
B. A syntax error, because mixed operators are forbidden
C. Y, because or is evaluated before and
D. Y, because DTL evaluates strictly left to right

50 A template uses {% for item in items %}{{ item }}{% empty %}No items{% endfor %}. Which input causes the empty branch to run without requiring a separate {% if %}?

for loop and if-else statements Hard
A. A one-element list containing ""
B. A queryset containing None
C. An empty queryset
D. A queryset whose objects are false-like

51 A view returns TemplateResponse(request, "report.html", context) and middleware must add context before rendering. Which statement accurately describes this response?

Dynamic Templates in Django Hard
A. Template rendering finishes before the view returns
B. Context processors run only when the view builds the response
C. Template rendering is deferred until response content is needed
D. Middleware cannot change the context after the view returns

52 A template rendered with render(request, "page.html", context) can access request.user, but the same template rendered with Template("...").render(Context(context)) cannot. What best explains the difference?

Dynamic Templates in Django Hard
A. render() uses a request-aware context and configured processors
B. Context exposes request data only when DEBUG=True
C. render() copies user data directly into every context
D. Template.render() automatically strips authenticated users

53 A child template contains visible HTML before {% extends "base.html" %}. What is the correct diagnosis under Django template inheritance rules?

Working with Template inheritance Hard
A. extends may appear anywhere if its argument is a string literal
B. The preceding HTML is prepended to the rendered parent template
C. The preceding HTML is automatically inserted into the first block
D. extends must be the first template tag to control inheritance

54 A base template defines {% block title %}Default{% endblock %}. A child overrides it with {% block title %}Report | {{ block.super }}{% endblock %}. What does the child render for that block?

Working with Template inheritance Hard
A. Report | Default
B. Default | Report
C. Report |
D. Report | {{ block.super }}

55 A child template attempts to define two blocks named content at the same inheritance level because the base appears to use that block in two places. Why is this invalid?

Working with Template inheritance Hard
A. A block name may be defined only once in one template
B. A child may override only the final block in its parent
C. Repeated blocks are allowed only inside {% include %}
D. Block names must be globally unique across the project

56 A developer sets DEBUG=True on a publicly reachable deployment to inspect an exception. Which statement identifies the primary Django-specific risk?

Debugging Django applications Hard
A. Django automatically grants staff permissions to all visitors
B. CSRF middleware is disabled for every unsafe request
C. Technical error pages may expose settings, paths, and request data
D. Database queries stop using parameter binding while debugging

57 A view accepts a password parameter and may raise an exception. Which Django mechanism is designed to prevent that parameter's value from appearing in technical error reports?

Debugging Django applications Hard
A. Decorate the view with @sensitive_post_parameters("password")
B. Decorate the view with @require_POST("password")
C. Mark the value by calling mark_safe(password)
D. Wrap the view with @csrf_protect("password")

58 A test must verify that a POST endpoint rejects requests lacking a CSRF token. Why can a default django.test.Client produce a misleading result, and what should the test use?

Testing in Django Hard
A. The default client skips CSRF checks; use Client(enforce_csrf_checks=True)
B. The default client converts POST to GET; use AsyncClient() instead
C. The default client adds a valid token; use Client(csrf_checks=False)
D. The default client disables middleware; use RequestFactory() instead

59 A TestCase registers a callback with transaction.on_commit() and expects the callback to run normally before the test method ends, but it never does. What is the most appropriate testing approach?

Testing in Django Hard
A. Replace on_commit() with setUpTestData()
B. Use captureOnCommitCallbacks() or a TransactionTestCase
C. Enable DEBUG=True before registering the callback
D. Call transaction.commit() directly inside the TestCase

60 A test class needs database objects created once for the class and then available with isolated in-memory field state in each test method. Which Django testing feature is intended for this?

Testing in Django Hard
A. TestCase.setUpTestData()
B. TestCase.setUp()
C. TransactionTestCase.tearDown()
D. SimpleTestCase.setUpClass()