Django MCQ3
Django MCQ3
A. web framework
C. analysis tool
Explanation:
Django is a Python-based web framework that is free and open-source. Django follows the model–
template–views architectural pattern.
A. Oracle
B. Microsoft Corporation
Explanation:
A. model–template–views
B. make–test–views
C. model–template–verify
D. mobile–template–verification
Answer: A) model–template–views
Explanation:
Explanation:
The original authors of Django are Adrian Holovaty and Simon Willison.
Explanation:
The command to create the first project in Django (Run this command in the command prompt) is:
A. MySQL
B. SQLite
C. Oracle
Answer: B) SQLite
Explanation:
Explanation:
8. Which is the correct command to start the Django development server on your system?
A. py manage.py localhost
B. py manage.py runatserver
C. py manage.py createserver
D. py manage.py runserver
Explanation:
The correct command to start the Django development server on your system is:
py manage.py runserver
A. settings.py
B. manage.py
C. templates.py
D. py manage.py runserver
Answer: C) templates.py
Explanation:
A. C++
B. Python
C. AngularJS
D. Asp.Net
Answer: B) Python
Explanation:
Django is a free and open-source web framework, it is written in Python programming language.
11. Which Django functions are used to take http requests and return http responses?
A. Django views
C. Django templates
D. Both A and B
Explanation:
To take http requests and return http responses, Django views are used which are Python functions.
A. tables
B. views
C. templates
D. objects
Answer: D) objects
Explanation:
A. models
B. views
C. templates
D. database
Answer: A) models
Explanation:
14. Which is the correct statement to import models in the Django project?
Explanation:
B. py migrate
C. py manage.py pymigrate
D. py manage.py migrate
Explanation:
A. run shell
B. py manage.py shell
D. py manage.py djangoshell
Explanation:
py manage.py shell
17. What is the correct syntax to use a variable in the Django template?
A. {{ variable_name }}
Answer: A) {{ variable_name }}
Explanation:
If you want to use a variable in the Django template, you need to follow the below-given syntax:
{{ variable_name }}
Let's suppose there is a variable named "email", and you want to use it inside a Django template.
Then you have to write it inside the double curly opening and closing braces.
18. Which Django file contains all the configuration of your Django installation?
A. main.py
B. setting.py
C. djangosetting.py
D. settings.py
Answer: D) settings.py
Explanation:
The settings.py file contains all the configurations of your Django installation.
19. How you can turn off the debugging in Django's configuration file?
A. DEBUG = false
B. DEBUG = FALSE
C. DEBUG = False
D. DEBUGOFF = True
Explanation:
You can turn off the debugging by writing DEBUG = False in Django's configuration file.
20. Which template tag is used to create variables directly in the Django template?
A. {% with %}
D. {{ with }}
Answer: A) {% with %}
Explanation:
You can use {% with %} template tag inside the Django template to create variables directly. Consider
the below example –
{% with name="Alvin" %}
{% endwith %}
A. empty
B. firstempty
C. firstemptyvar
D. firstof
Answer: D) firstof
Explanation:
The firstof is a Django template tag that is used to return the first not empty variable. Consider the
below syntax –
A. 1
B. 2
C. 3
D. 4
Answer: C) 3
Explanation:
Th render() function takes 3 parameters, which are request, template, and context_dictionary.
Consider the below syntax –
23. Which is the correct import statement to use the render() function in Django?
Explanation:
The correct import statement to use the render() function in Django is:
from django.shortcuts import render
Explanation:
The Django tag comment is used to write comment. Here is the syntax of comment tag -
Example:
<h1>My page</h1>
{% comment %}
<h1>Hello, world!</h1>
{% endcomment %}
25. Except Django comment tag, what can be used to write smaller comments?
A. # ..
B. /* … *
D. {# ... #}
Answer: D) {# ... #}
Explanation:
The {# ... #} tag can also be used to write smaller comments. Below is the syntax –
{# ... #}
Example:
A. # ..
B. /* … *
D. {# ... #}
Answer: A) # ...
Explanation:
Django views are Python functions i.e., they are written in Python. Thus, the Python
comment character (#) can be used to write comments in Django views. Consider the below example
–
def testing_function(request):
templateObj = loader.get_template('template_student.html')
#context = {
# 'var1': 'John',
#}
return HttpResponse(templateObj.render())
27. Which Django tag is used to include a template inside the current template?
A. allow
B. insert
C. import
D. include
Answer: D) include
Explanation:
The Django tag include is used to include a template inside the current template. Consider the
below-given example in which we are importing a templated named "students.html" inside the
current template –
{% include 'students.html' %}
A. send
B. go
C. export
D. with
Answer: D) with
Explanation:
You can use the with keyword to send variables into the template. Consider the below-given example
–
29. In Django QuertSet, which method is used to get all the records and fields of a given model?
A. get()
B. all()
C. getall()
D. bunch()
Answer: B) all()
Explanation:
In Django QuertSet, the all() method is used to get all the records and fields of a given model.
Consider the below code statement in which we are getting all records –
dataObj = students.objects.all()
30. In Django QuertSet, which method is used to get each object as a Python dictionary, with the
names and values as key/value pairs?
A. values()
B. dictionary()
C. getvalues()
Answer: A) values()
Explanation:
In Django QuertSet, the values() method is used to get each object as a Python dictionary, with the
names and values as key/value pairs. Consider the below code statement –
dataObj = students.objects.all().values()
31. In Django QuertSet, which method is used to get the specified column?
A. column_values()
B. columnvalues()
C. values_list()
D. column_list()
Answer: C) values_list()
Explanation:
In Django QuertSet, the values_list() method is used to get the specified column. Consider the below
code statement –
dataObj = students.objects.values_list('class')
Where, "students" is the model name, and "class" is the column name.
A. filter()
B. search()
C. filter_all()
D. filter_values()
Answer: A) filter()
Explanation:
In Django QuertSet, the filter() method is used to filter your search and returns the rows only that
match the search query. Consider the below code statement –
dataObj = students.objects.filter(class='B.tech').values()
Where, "students" is the model name, and "class" is the column name. The above statement will
return only matched rows.
Learn: Django – How to filter empty or NULL names in a QuerySet?
Explanation:
In Django QuertSet, the filter() method is used to filter your search and returns the rows only that
match the search query. If you want to add more than one query, you can place them by separating
them with commas. Consider the below code statement –
Where, "students" is the model name, and "class" is the column name. The above statement will
return only matched rows.
A. sort()
B. sort_by()
C. order_by()
D. order()
Answer: C) order_by()
Explanation:
The order_by() method is used to sort a Django QuerySet. Consider the below code statement –
dataObj = students.objects.all().order_by('name').values()
Where, "students" is the model name, and "name" is the column name. The above statement will
sort the QuerySet based on the names.
35. Which Django tag is used to insert the current date and time?
A. date
B. now
C. datetime
D. currentdatetime
Answer: B) now
Explanation:
The Django tag now is used to insert the current date and/or time. Consider the below syntax –
{% now format %}
Example:
Output:
2023-07-17