Preparing to build a career in Django? This Django MCQs collection is designed to help you test your knowledge of Django fundamentals, project configuration, URL routing, views, templates, models, ORM, forms, authentication, middleware, testing, security, APIs, deployment, and practical Django development.
Note: Score 60% or higher to unlock an exclusive offer of up to 50% off on all of our self-paced Django courses.
Let's begin!
1. What is Django primarily used for?
2. Which architectural pattern is Django commonly described as following?
3. Which Python package provides Django's core framework?
4. Which command creates a new Django project?
5. Which command creates a new Django application inside a project?
6. What is a Django app?
7. Which file commonly contains project-level URL configuration?
8. Which file commonly defines Django model classes for an app?
9. What does manage.py primarily provide?
10. Which command starts Django's development server?
11. Where are installed Django apps commonly listed?
12. Which setting defines the root URL configuration module?
13. Which setting identifies the Django settings module used by a project?
14. What is the purpose of ALLOWED_HOSTS?
15. Which setting controls Django's debug mode?
16. Why should DEBUG generally be disabled in production?
17. Which setting configures the database connection?
18. What does TIME_ZONE control?
19. What does SECRET_KEY protect and support?
20. Why are environment variables commonly used for production Django settings?
21. Which function is commonly used to define URL patterns?
22. Which module provides path() for URL routing?
23. What does a URL pattern map to?
24. What is the purpose of a named URL pattern?
25. Which function is commonly used to generate a URL from its name in templates?
26. Which shortcut commonly renders a template and returns an HTTP response?
27. What does redirect() commonly return?
28. What is the purpose of get_object_or_404()?
29. Which request attribute commonly contains query-string parameters?
30. Which request attribute contains submitted form data for POST requests?
31. Which syntax outputs a variable in a Django template?
32. Which syntax is used for Django template tags?
33. Which syntax is used for Django template comments?
34. What does template inheritance allow?
35. Which tag is commonly used to declare a parent template?
36. Which tag defines an overridable section in a base template?
37. Which setting commonly identifies the URL prefix for static files?
38. Which Django template tag is commonly used to build a static-file URL?
39. What is collectstatic primarily used for?
40. Why should user-uploaded media generally be distinguished from static assets?
41. What does a Django model generally represent?
42. Which base class do standard Django models inherit from?
43. Which field stores a short string with a maximum length?
44. Which field is commonly used for longer text?
45. Which field stores true/false values?
46. Which field is commonly used for dates and times?
47. What does ForeignKey represent?
48. Which field represents a many-to-many relationship?
49. Which field represents a one-to-one relationship?
50. In modern Django, what can CompositePrimaryKey define?
51. What is a QuerySet?
52. Which method retrieves all objects as a QuerySet?
53. Which method filters a QuerySet by conditions?
54. Which method is commonly used when exactly one object is expected?
55. What happens when QuerySet evaluation is usually delayed?
56. Which method can force evaluation by returning a Python list?
57. What is select_related() primarily used for?
58. What is prefetch_related() primarily used for?
59. Which method returns only selected field values as dictionaries?
60. Which method can update matching rows directly in the database?
61. What is a Django Form primarily used for?
62. What is a ModelForm?
63. Which method validates submitted form data?
64. Where is validated form data commonly available after successful validation?
65. Which method can be overridden for cross-field validation?
66. What is the purpose of a field's required option?
67. What does a form's errors attribute contain?
68. Why is a POST form commonly protected with CSRF middleware and token?
69. Which template tag inserts a CSRF token into a form?
70. When should a ModelForm commonly be used?
71. Which Django app provides the built-in authentication framework?
72. What does authenticate() typically do?
73. What does login() do?
74. What does logout() do?
75. Which attribute commonly identifies the currently authenticated user on a request?
76. Which decorator can restrict a view to authenticated users?
77. What is a Django permission?
78. What is a Group commonly used for?
79. Why should passwords not be stored as plain text?
80. Which Django component provides configurable password validators?
81. What is Django middleware?
82. Where are middleware classes commonly configured?
83. What can middleware do?
84. Which middleware provides CSRF protection in a standard Django setup?
85. Which middleware commonly manages sessions?
86. What does AuthenticationMiddleware add to the request?
87. Why does middleware order matter?
88. What is a process_view middleware hook used for?
89. What is a process_exception hook intended to handle?
90. What is ASGI useful for in Django?
91. What is Django admin primarily designed for?
92. How do you make a model available in the default admin?
93. What does makemigrations create?
94. What does migrate do?
95. Why are migrations important?
96. Which command creates a Django superuser interactively?
97. What does showmigrations display?
98. What does the Django check command help with?
99. What is a custom management command?
100. In Django 5.2+, what notable shell behavior was introduced?
101. Which Django module provides tools for writing tests?
102. Which test class is commonly used for Django tests that interact with the database?
103. What is the Django test client used for?
104. Which assertion checks that a response returned a particular status code?
105. What is the purpose of assertRedirects()?
106. What is TransactionTestCase useful for?
107. Why are tests valuable in Django projects?
108. What does DEBUG help developers with during development?
109. Why should sensitive production settings not be copied into tests unnecessarily?
110. What is query-count testing useful for?
111. What attack does Django's CSRF protection primarily address?
112. What does Django's template autoescaping help reduce?
113. Why should raw SQL be used carefully?
114. Which ORM practice helps avoid unsafe string-built SQL?
115. What does SecurityMiddleware provide?
116. What is SECURE_SSL_REDIRECT used for?
117. What does SESSION_COOKIE_SECURE generally require?
118. What does CSRF_COOKIE_SECURE generally control?
119. Why is clickjacking protection relevant to web applications?
120. What is a strong production practice for SECRET_KEY?
121. What is Django caching used for?
122. Which Django API can be used to cache a view response?
123. What is a common cause of the N+1 query problem?
124. Which ORM method often helps with N+1 problems for foreign-key relationships?
125. Which ORM method is commonly used for many-to-many or reverse relationships?
126. Why can database indexes improve performance?
127. What is a trade-off of adding many database indexes?
128. Why should pagination be used for large result sets?
129. What is connection reuse intended to reduce?
130. Why should expensive work sometimes be moved to background tasks?
131. Which package is widely used to build REST APIs with Django?
132. What is a serializer in Django REST framework commonly used for?
133. What does a ModelSerializer provide?
134. What is an APIView in Django REST framework?
135. What does a ViewSet commonly group?
136. Why should production database credentials be kept outside committed source code?
137. What is HTTPS important for Django applications?
138. What should a production deployment do with DEBUG?
139. What is a health check endpoint commonly used for?
140. Why are application logs important in production?
141. A page loops over 100 books and accesses each author's profile, causing many database queries. What should you evaluate first?
142. A view needs to return 404 when a requested object does not exist. Which approach is concise and idiomatic?
143. An application needs to update several related database records atomically. Which Django feature should be evaluated?
144. A developer changes a model field and deploys without creating a migration. What is the main risk?
145. A user submits invalid form data and the page should display field-level errors. What should the view typically do?
146. An API endpoint should allow authenticated users to read data but only staff users to modify it. What should be configured?
147. A production app exposes a detailed Django traceback to visitors. Which setting should be checked first?
148. A search endpoint builds raw SQL by concatenating a query parameter. What is the primary concern?
149. A Django 5.2 project needs a primary key composed of two model fields. Which feature is relevant?
150. A Django application is being upgraded and security fixes are available for the installed release. What is the appropriate production practice?