Académique Documents
Professionnel Documents
Culture Documents
1. What is the Django shortcut method to more easily render an html response?
render_to_html
render_to_response
response_render
render
2. By using django.contrib.humanize, you can use the following filter in your template to display the
number 3 as three.
apnumber
intcomma
intword
ordinal
3. How do you concatenate two QuerySets into one list?
result = list(query_set_1 | query_set_2)
from itertools import chain result = list(chain(query_set_1, query_set_2))
from django.db.models import Q result = Q(query_set_1) | Q(query_set_1)
result = query_set_1 + query_set_2
4. What is the Django command to start a new app named ‘users’ in an existing project?
manage.py –newapp users
manage.py newapp users
manage.py –startapp users
manage.py startapp users
5. What are the features available in Django web framework?
Admin Interface (CRUD)
Templating
Form handling
All of the above
6. What are the advantages of using Django for web development?
It facilitates you to divide code modules into logical groups to make it flexible to change
It provides auto-generated web admin to make website administration easy
It provides pre-packaged API for common user tasks
All of the above
7. What is the most easiest, fastest, and most stable deployment choice in most cases with Django?
FastCGI
mod_wsgi
SCGI
AJP
8. What happens if MyObject.objects.get() is called with parameters that do not match an existing item in
the database?
The Http404 exception is raised
The DatabaseError exception is raised
The MyObject.DoesNotExist exception is raised
The object is created and returned
9. What Commands are used to create a project in Django?
Project
_init_.py
manage.py
All of the above mentioned
10. What is the Django command to view a database schema of an existing (or legacy) database?
manage.py legacydb
django-admin.py schemadump
manage.py inspect
manage.py inspectdb
11. The architecture of Django consists of?
Models
Views
Templates
All of these
12. What does of Django field class types do?
The database column type
The default HTML widget to avail while rendering a form field
The minimal validation requirements used in Django admin
All of the above
13. What is the purpose of settings.py?
To configure settings for the Django project
To configure settings for an app
To set the date and time on the server
To sync the database schema
14. What are the caching strategies in Django?
File system caching
In-memory caching
Both 1st and 2nd
None
15. In Django how would you retrieve all the ‘User’ records from a given database?
User.objects.all()
Users.objects.all()
User.all_records()
User.object.all()
16. What are Migrations in Django?
Migrations are files where Django stores changes to your models.
They are files saved in migrations directory.
They are created when you run make migrations command.
All of the above
17. What is Post.objects.all() is used for?
It is used to bring all the objects stored in Post table.
It is used to create a new Post object m.
Post object will bring objects from database with SQL Query: Select *.
None of the above
18. In Post.models.filter() you can pass multiple parameters in filter() to narrow your result/s.
True
False
19. What will happen on execution of this command : > python manage.py createsuperuser
It will create an admin superuser.
It will ask for name and password of the superuser.
Both 1st and 2nd
None of the above
20. What kind of non-HTML outputs can Django generate?
.epub Files
Sitemaps (an XML format developed by Google)
Exe files
Python files
21. Which code will give us a text area form field?
Field_name = forms.TextAreaField()
Field_name = forms.CharField(widgets = forms.Textarea)
Field_name = forms.TextField(widgets = forms.Textarea)
None of the above
22. Django’s GeoDjango app is used for?
To make Django work efficiently with maps.
To make it input structural data.
To make it a Web-based CAD System.
None of the above
23. Suppose I have a Python class like this. Now, if we pass the obj in a context variable and add the
template like this. {{ obj.topic }} Which value will the template engine return?
C:\Users\hp>django-admin shell
Python 3.7.6 (tags/v3.7.6:43364a7ae@, Dec 19 2019, 90:42:30) [MSC v.1916 64 bit (AMD64)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> class DataFlair:
cee topic = "Django Framework"
an def topic():
cee return topic
>>> obj = DataFlair()
>>>
topic attribute
topic method
throw an error
Return empty string
23. What is the purpose of this code?
C:\Users\hp>django-admin shell
Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2619, 00:42:30) [MSC v.1916 64 bit (AMD64)]
on win32
Type "help", “copyright", “credits” or “license” for more information.
(InteractiveConsole)
>>> from django.core.signing import Signer
>>> DataFlair = Signer()
Cryptographic Signing
Signature classes to retain signatures
Handwriting recognition classes in Django
None of the above
24. This is a code_snippet to mail a person. There are several cases where people might just give the
wrong email. The mail errors may be unhandled. How can we ignore the errors which mail generates?
C:\Users\hp>django-admin shell °
Python 3.7.6 (tags/v3.7.6:43364a7ae@, Dec 19 2019, 60:42:36) [MSC v.1916 64 bit (AMD64)]
on win32
Type “help”, “copyright”, "credits" or “license” for more information.
(InteractiveConsole)
>>> from django.core.mail import send_mail
>>> send_mail(‘DataFlair',
... ‘Django Tutorials',
... ‘DataFlair@django.com',
... ['karanshyammittal@gmail.com'],
...)
The send_mail() shall have a handler which can handle such errors.
The parameter fail_silently shall be added and its value shall be true.
The mail will provide other functions then send_mail() to handle the error.
None of the above