Reference:
Django comes with a robust cache system that lets you save dynamic pages, so they don’t have to be computed for each request. For convenience, Django offers cache with different granularity — from entire website to pages to part of pages to DB query results to any objects in memory. Cache middleware. If enabled, each Django-powered page will be cached based on URL.
Q2. In which programming language is Django written?
C++
Java
Python
Ruby
Q3. To automatically provide a value for a field, or to do validation that requires access to more than a single field, you should override the ___ method in the ___ class.
validate(); Model
group(); Model
validate(); Form
clean(); Field
Q4. A client wants their site to be able to load "Rick & Morty" episodes by number or by title—e.g., shows/3/3 or shows/picklerick. Which URL pattern do you recommend?
Q5. How do you determine at startup time if a piece of middleware should be used?
Raise MiddlewareNotUsed in the init function of your middleware.
Implement the not_used method in your middleware class.
List the middleware beneath an entry of django.middleware.IgnoredMiddleware.
Write code to remove the middleware from the settings in [app]/init.py.
Q6. How do you turn off Django’s automatic HTML escaping for part of a web page?
Place that section between paragraph tags containing the autoescape=off switch.
Wrap that section between { percentage mark autoescape off percentage mark} and {percentage mark endautoescape percentage mark} tags.
Wrap that section between {percentage mark autoescapeoff percentage mark} and {percentage mark endautoescapeoff percentage mark} tags.
You don't need to do anything—autoescaping is off by default.
Q7. Which step would NOT help you troubleshoot the error "django-admin: command not found"?
Check that the bin folder inside your Django directory is on your system path.
Make sure you have activated the virtual environment you have set up containing Django.
Check that you have installed Django.
Make sure that you have created a Django project.
Q8. Every time a user is saved, their quiz_score needs to be recalculated. Where might be an ideal place to add this logic?
template
model
database
view
Q9. What is the correct way to begin a class called "Rainbow" in Python?
Rainbow {}
export Rainbow:
class Rainbow:
def Rainbow:
Q10. You have inherited a Django project and need to get it running locally. It comes with a requirements.txt file containing all its dependencies. Which command should you use?
django-admin startproject requirements.txt
python install -r requirements.txt
pip install -r requirements.txt
pip install Django
Q11. Which best practice is NOT relevant to migrations?
To make sure that your migrations are up to date, you should run updatemigrations before running your tests.
You should back up your production database before running a migration.
Your migration code should be under source control.
If a project has a lot of data, you should test against a staging copy before running the migration on production.
Q12. What will this URL pattern match? url(r'^$', views.hello)
a string beginning with the letter Ra string beginning with the letter R
an empty string at the server root
a string containing ^ and $a string containing ^ and $
an empty string anywhere in the URLan empty string anywhere in the URL
Q13. What is the typical order of an HTTP request/response cycle in Django?
URL > view > template
form > model > view
template > view > model
URL > template > view > model
Q14. Django's class-based generic views provide which classes that implement common web development tasks?
concrete
thread-safe
abstract
dynamic
Q15. Which skills do you need to maintain a set of Django templates?
template syntax
HTML and template syntax
Python, HTML, and template syntax
Python and template syntax
Q16. How would you define the relationship between a star and a constellation in a Django model?
Q17. Which is NOT a valid step in configuring your Django 2.x instance to serve up static files such as images or CSS?
In your urls file, add a pattern that includes the name of your static directory.
Create a directory named static inside your app directory.
Create a directory named after the app under the static directory, and place static files inside.
Use the template tag {percentage mark load static percentage mark}.
Q18. What is the correct way to make a variable available to all of your templates?
Set a session variable.
Use a global variable.
Add a dictionary to the template context.
Use RequestContext.
Q19. Should you create a custom user model for new projects?
No. Using a custom user model could break the admin interface and some third-party apps.
Yes. It is easier to make changes once it goes into production.
No. Django's built-in models.User class has been tried and tested—no point in reinventing the wheel.
Yes, as there is no other option.
Q20. You want to create a page that allows editing of two classes connected by a foreign key (e.g., a question and answer that reside in separate tables). What Django feature can you use?
actions
admin
mezcal
inlines
Q21. Why are QuerySets considered "lazy"?
The results of a QuerySet are not ordered.
QuerySets do not create any database activity until they are evaluated.
QuerySets do not load objects into memory until they are needed.
Using QuerySets, you cannot execute more complex queries.
Q22. You receive a MultiValueDictKeyError when trying to access a request parameter with the following code: request.GET['search_term']. Which solution will NOT help you in this scenario?
Switch to using POST instead of GET as the request method.
Make sure the input field in your form is also named "search_term".
Use MultiValueDict's GET method instead of hitting the dictionary directly like this: request.GET.get('search_term', '').
Check if the search_term parameter is present in the request before attempting to access it.
Q23. Which function of Django's Form class will render a form's fields as a series of <p> tags?
show_fields()
as_p()
as_table()
fields()
Q24. You have found a bug in Django and you want to submit a patch. Which is the correct procedure?
Fork the Django repository GitHub.
Submit a pull request.
all of these answers.
Run Django's test suite.
Q25. Django supplies sensible default values for settings. In which Python module can you find these settings?
django.utils.default_settings.py
django.utils.global_settings.py
django.conf.default_settings.py
django.conf.global_settings.py
Q26. Which variable name is best according to PEP 8 guidelines?
numFingers
number-of-Fingers
number_of_fingers
finger_num
Q27. A project has accumulated 500 migrations. Which course of action would you pursue?
Manually merge your migration files to reduce the number
Don't worry about the number
Try to minimize the number of migrations
Use squashmigrations to reduce the number
Q28. What does an F() object allow you when dealing with models?
perform db operations without fetching a model object
define db transaction isolation levels
use aggregate functions more easily
build reusable QuerySets
Q29. Which is not a Django field type for holding integers?
SmallIntegerField
NegativeIntegerField
BigAutoField
PositiveIntegerField
Q30. Which will show the currently installed version?
print (django.version)
import django django.getVersion()
import django django.get_version()
python -c django --version
Q31. You should use the http method ___ to read data and ___ to update or create data
READ; WRITE
GET; POST
POST; GET
GET; PATCH
Q32. When should you employ the POST method over GET for submitting data?
when efficiency is important
when you want the data to be cached
when you want to use your browser to help with debugging
when the data in the form may be sensitive
Q33. When to use the Django sites framework?
if your single installation powers more than one site
if you need to serve static as well as dynamic content
if you want your app have a fully qualified domain name
Q37. What is a callable that takes a value and raises an error if the value fails?
validator
deodorizer
mediator
regular expression
Q38. To secure an API endpoint, making it accessible to registered users only, you can replace the rest_framework.permissions.allowAny value in the default_permissions section of your settings.py to
rest_framework.permissions.IsAdminUser
rest_framework.permissions.IsAuthenticated
rest_framework.permissions.IsAuthorized
rest_framework.permissions.IsRegistered
Q39. Which command would you use to apply a migration?
makemigration
update_db
applymigration
migrate
Q40. Which type of class allows QuerySets and model instances to be converted to native Python data types for use in APIs?
objectwriters
serializers
picklers
viewsets
Q41. How should the code end?
{ percentage if spark >= 50 percentage }
Lots of spark
{percentage elif spark == 42 percentage}
{ percentage else percentage}
{percentage endif percentage}
Nothing needed
{percentage end percentage}
Q42. Which code block will create a serializer?
from rest_framework import serializers
from .models import Planet
Q56. Which generic view should be used for displaying the titles of all Django Reinhardt's songs?
DetailView
TittleView
SongView
ListView
Q57. Which statement is most accurate, regarding using the default SQLite database on your local/development machine but Postgres in production
There's less chance of introducing bugs since SQLite already works out the box
It's fine, you just need to keep both instances synchronized
It's a bad idea and could lead to issues down the road
It's the most efficient way to build a project
Q58. Why might you want to write a custom model Manager?
to perform database queries
to set up a database for testing
to modify the initial QuerySet that the Manager returns
to filter the results that a database query returns
Q59. In Django, what are used to customize the data that is sent to the templates?
models
views
forms
serializers
Q60. To complete the conditional, what should this block of code end with?
%if sparles >= 50 % Lots of sparkles!
%elif sparkles == 42 % The answer to life, the universe, and everything!
% endif %
Nothing else is needed.
% end%
% else %
Q61. When should you employ the POST method over the GET method for submitting data from a form?
when the data in the form may be sensitive
when you want the data to be cached
when you want to use your browser to help with debugging
when efficiency is important
Q62. What is a callable that takes a value and raises an error if the value fails to meet some criteria?
mediator
validator
regular expression
deodorizer
Q63. You are uploading a file to Django from a form and you want to save the received file as a field on a model object. You can simply assign the file object from**_to a field of type__**in the model.
request.META; FileField
request.FILES; BLOBField
request.FILES; FileField
request.META.Files; CLOBField
Q64. What python module might be used to store the current state of a Django model in a file?
pickle
struct
marshal
serialize
Q65. To add a new app to an existing Django project, you must edit the _ section of the _ file.
ALLOWED_HOSTS; settings.py
APPS; manage.py
INSTALLED_APPS; settings.py
TEMPLATES; urls.py
Q66. Which is not a third-party package commonly used for authentication?
django-guardian
django-rest-auth
authtoken
django-rest-framework-jwt
Q67. Which function in the django.urls package can help you avoid hardcoding URLS by generating a URL given the name of a view?
get_script_prefix()
redirect()
reverse()
resolve()
Q68. Which is Fictional HTTP request method?
POST
PUT
PAUSE
PATCH
Q69. Which helper function is not provided as a part of django.shortcuts package? ref-
Q84. Which of the following is true about Django's Object-Relational Mapping (ORM)?
It's used to define URL routing in a Django application.
It allows you to query the database using Python code.
It's used to define the structure of HTML templates.
It's responsible for managing user authentication.
Q85. Which of the following is true about Django's "many-to-many" field in a model?
It's used to define a one-to-one relationship between two models.
It creates a foreign key relationship between two models.
It allows multiple objects to be associated with each other.
It enforces unique constraints on a field.
Q86. Django's class-based generic views provide which classes that implement common web development tasks?
concrete
thread-safe
abstract
dynamic
Q87. Which skills do you need to maintain a set of Django templates?
template syntax
HTML and template syntax
Python, HTML, and template syntax
Python and template syntax
Q88. Which is a nonstandard place to store templates?
at the root level of a project
inside the application
in the database
on Github
Q89. If you left the 8080 off the command python manage.py runserver 8080 what port would Django use as default?
8080
80
8000
It would fail to start
Q90. What is the purpose of Django's Object-Relational Mapping (ORM)?
To define URL routing in a Django application.
To handle HTTP requests and responses globally.
To map Python objects to database tables and simplify database operations.
To create user interfaces.
Q91. In Django, what does the term "migration" refer to?
A change in URL routing configuration.
The process of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema.
A way to define custom middleware.
The process of creating HTML templates for your application.
Q92. What is the purpose of Django's "context" in the context of rendering templates?
To pass data from your views to your templates so that the data can be rendered dynamically.
To define URL patterns for your application.
To manage HTTP requests and responses.
To create user interfaces.
Q93. What does the Django QuerySet class represent?
A Python class used for defining URL routing in Django.
A class for managing HTTP requests and responses.
A database query made by Django, represented in Python.
A class for defining HTML templates.
Q94. In Django, what is the purpose of the "collectstatic" management command?
To collect user data for analytics.
To collect database records from multiple sources.
To collect all static files (CSS, JavaScript, images) from each of your applications into a single location.
To collect logs for debugging purposes.
Q95. What is the Django Admin site used for?
To manage user authentication.
To define URL routing for Django applications.
To provide an automatically generated admin interface for your models.
To write and run database queries.
Q96. What does Django's "middleware" refer to?
A way to create user interfaces.
A database query in Django.
A way to process HTTP requests and responses globally before they reach the view or after they leave the view.
A way to configure URL routing in Django.
Q97. What is the primary purpose of Django's "migration files"?
To define and store changes to the database schema over time.
To manage static files like CSS and JavaScript.
To configure URL patterns.
To create HTML templates.
Q98. Which authentication system does Django provide out of the box?
OAuth 2.0
User authentication with built-in user models and views.
JWT (JSON Web Tokens)
SAML (Security Assertion Markup Language)
Q99. In Django, what does the "Model-View-Controller" (MVC) architectural pattern refer to?
A pattern for defining URL routing.
A pattern for creating HTML templates.
A pattern that divides the application into three interconnected components: Model, View, and Controller (Django often refers to it as MTV, Model-View-Template).
A pattern for user authentication.
Q100. What is the purpose of Django's "templates"?
To define database schema and model relationships.
To define the structure and layout of HTML pages to be served to the user.
To configure URL patterns for your application.
To store and serve static files like images and JavaScript.