django mcq questions


 


1.What happens when url.py file is edited while the development server is still  running?

 A. Development server terminates.

 B. The development server automatically restarts.

 C. The development server does nothing.

 D. The web page is automatically reloaded.

2.Which setting contains the parameter of main-urls file?

 A. ROOT_URLCONF

 B. MAIN_URLCONF

 C. STATIC_URL

 D. MEDIA_URL

3. Django is based on which framework?

 A. MVC

 B. MVVM

 C. MVT or MTV (Model-View-Template)

 D. None of the above

4.What is the purpose of __init__.py in project directories?

 A. It allows Python to recognise the folder as package.

 B. It is useless and can be deleted.

 C. It is used to initialise any empty values.

 D. None of the above

5.What happens when url.py file is edited while the development server is still running?

 A. Development server terminates.

 B. The development server automatically restarts.

 C. The development server does nothing.

 D. The web page is automatically reloaded.

6.Which method is used instead of path() in urls.py to pass in regular expressions as routes?
 
A. static()
B. re_path()
C. include()
D. url()

7.What happens if, from the given list, I searched for urlpatterns registration/ skipping the trailing/slash?
urlpatterns = [
    path(‘admin/’, admin.site.urls),
    path(‘registration/’, include(‘registrations.urls’)),
    path(”, include(‘home.urls’)),
    path(‘design’, include(‘design.urls’)),
    # DataFlair #Ajax
    # ———————————
    path(‘ajax/’, include(‘post.urls’)),
    # ———————————
]

 A. Django will give a 404-error page.
 B. Django will match registration/ pattern.

8.What is the use of os.path.dirname(__file__) in this method?

 A. It is the default value and points to Django settings.py.
 B. It is passing some value defined before.
 C. It is used to pass the value of current file in which this line is written.
 D. None of the above

9.
What does {{ name }} this mean in Django Templates?

 A. It will be displayed as name in HTML.
 B. The name will be replaced with values of Python variable.
 C. {{ name }} will be the output.
 D. None of the above

10.Check in-valid template tag.

 A. {% If %}/ {% else %}
 B. {% ifequal %}
 C. {% while %} – wrong
 D. {% for key in dictionary %}

11.What will this template generate

    #body-start

   {% if (iterator) in list %}
   {{ iterator }}
   {% endif %}

   #body-end

 A. Error-invalid syntax
 B. An iterator in list
 C. Logic does not run
 D. None of the above

12.What does {{ forloop.counter }} prints?

 A. It will not print if for loop variable is not defined.
 B. It will count the number of times loop ran.
 C. It prints the integer value of no. of times the loop executed.
 D. None of the above

13.This template {# #} is used for?

 A. It is comment in template language.
 B. It is used for business logic.
 C. It will raise an exception.
 D. None of the above

14.Suppose you want to count the number of books in Django.
books = Book.objects.all()
Which implementation would be fastest?

 A. Database level Implementation – books.count()
 B. Python Implementation – len(books)
 C. Template Language Implementation – {{ books | length }}
 D. None of the above

15.From the previous question, suppose we want to implement the Query in the template. Choose one option which provides an optimal solution.

 A. {{ books | length }}
 B. {{ books.count }}
 C. {{ forloop.counter }} inside forloop over books Context Variable
 D. None of the above

16.Which of these commands is not a management command of staticfiles?

 A. python manage.py collectstatic
 B. python manage.py findstatic
 C. python manage.py runserver –nostatic
 D. python manage.py makemigrations 

17.What data types and objects are not accepted as an argument by Paginator class?

 A. Dictionary
 B. Tuple
 C. List
 D. Queryset
 E. None of the above

18.Which of these is not a valid method or approach to perform URL resolution?

 A. Using Template {{ url : }} in template
 B. Using reverse() in View Functions
 C. Using get_absolute_url()
 D. None of the above

19.Which of the following Password Validators are not provided by default in Django?

 A. NumericPasswordValidator
 B. CommonPasswordValidator
 C. MinimumLengthValidator
 D. MaximumLengthValidator

20.Which of these are not built-in Validators in Django?

 A. MinLengthValidator
 B. EmailValidator
 C. ProhibitNullCharacterValidator
 D. None of the above

21.Which of these is not a step in Form Validation?

 A. to_python() method
 B. validate() method
 C. run_validators()
 D. clear()
 E. clean()

22.When we execute form.clean() on a form object and suppose at any point validation error is raised by a validator. What happens after the Validation Error occurs?

 A. The program stops executing and Django server stops.
 B. The clean() method stops validation and returns a list of validation errors.
 C. The clean() method continues execution and catches all the validation errors in      that form.
 D. The clean() method catches the validation error and corrects it.

23.What is the Django shortcut method to more easily render an html response?

A. render_to_html
B. render_to_response
C. response_render
D. render

24.By using django.contrib.humanize, you can use the following filter in your template to display the number 3 as three.
A. apnumber
B. intcomma
C. intword
D. ordinal

25.How do you concatenate two QuerySets into one list?

A. result = list(query_set_1 | query_set_2)
B. from itertools import chain result = list(chain(query_set_1, query_set_2))
C. from django.db.models import Q result = Q(query_set_1) | Q(query_set_1)
D. result = query_set_1 + query_set_2

26.What is the Django command to start a new app named 'users' in an existing project?

A. manage.py "“newapp users
B. manage.py newapp users
C. manage.py "“startapp users
D. manage.py startapp users

27.What are the features available in Django web framework?

A. Admin Interface (CRUD)
B. Templating
C. Form handling
D. All of the above

28.The architecture of Django consists of?

A. Models
B. Views
C. Templates
D. All of these

29.What does of Django field class types do?

A. The database column type
B. The default HTML widget to avail while rendering a form field
C. The minimal validation requirements used in Django admin
D. All of the above

30.What is the purpose of settings.py?

A. To configure settings for the Django project
B. To configure settings for an app
C. To set the date and time on the server
D. To sync the database schema

31. What are the caching strategies in Django?

A. File sytem caching
B. In-memory caching
C. Both A and B
D. None

32.In Django how would you retrieve all the 'User' records from a given database?

A. User.objects.all()
B. Users.objects.all()
C. User.all_records()
D. User.object.all()

33.What is the Django command to view a database schema of an existing (or legacy) database?

A. manage.py legacydb
B. django-admin.py schemadump
C. manage.py inspect
D. manage.py inspectdb

34. What Commands are used to create a project in Django?

A. Project
B. _init_.py
C. manage.py
D. All of the above mentioned

35.What happens if MyObject.objects.get() is called with parameters that do not match an existing item in the database?

A. The Http404 exception is raised
B. The DatabaseError exception is raised
C. The MyObject.DoesNotExist exception is raised
D. The object is created and returned

36.What is the most easiest, fastest, and most stable deployment choice in most cases with Django?

A. FastCGI
B. mod_wsgi
C. SCGI
D. AJP

37.What are the advantages of using Django for web development?
A. It facilitates you to divide code modules into logical groups to make it flexible to change
B. It provides auto-generated web admin to make website administration easy
C. It provides pre-packaged API for common user tasks
D. All of the above

38.Which of these variables are the settings for django.contib.staticfiles app?

A. STATIC_URL
B.STATIC_ROOT
C.STATICFILES_DIRS
D.All of the above

39.Django was introduced by ...................

A. Adrian Holovaty
B.Bill Gates
C.Rasmus Lerdorf
D.Tim Berners-Lee

40.django is written in which language?

A. PHP
B.Python
C.Java
D.Perl

41. What are Migrations in Django?

A. They are files saved in migrations directory.
B. They are created when you run makemigrations command.
C. Migrations are files where Django stores changes to your models.
D. All of the above

42.Django was initially released in ..................?

A. July 2005
B. July 2006
C. June 2005
D. None of above

43.Can I use Django offline?

A. Yes
B. No

44.Which of the following is the Django shortcut method to more easily render an html response?

A. render
B.response_render
C.render_to_response
D.render_to_html

45.Which Command is used to create a project in Django?

A. Project
B. manage.py
C. _init_.py
D. All of the above

46.What is the Django command to view a database schema of an existing (or legacy) database?

A. manage.py inspect
B.manage.py legacydb
C.manage.py inspectdb
D.None of the above

47. Django is a type of
A. Programming Language
B. Software
C. Web framework
D. None of above

48.What is a Django App?

A. Django app is an extended package with base package is Django
B. Django app is a python package with its own components.
C. Both 1 & 2 Option
D. All of the above

49.Django was designed to help developers take applications from concept to completion as quickly as possible.

A. True
B. False

50.Which file is kind of your project local django-admin for interacting with your project via command line?

A. settings.py
B. admin.py
C. models.py
D. manage.py

51.Render function takes ___________ parameters.

A. 1
B. 2
C. 3
D. 4

52. How many kinds of HTTP requests there in Django?

A. 2
B. 3
C. 4
D. 5


53.Which filter will truncate the string, so you will see only the first 80 words?

A. {{string|truncatewords}}
B. {{string|truncate:80}}
C. {{string|truncate}}
D. {{string|truncatewords:80}}

54. Suppose you want to count the number of books in Django.Which implementation would be fastest?

books = Book.objects.all()
A. Template Language Implementation – {{ books | length }}
B. Python Implementation – len(books)
C. Database level Implementation – books.count()
D. None of the above

55. What are some valid forloop attributes of Django Template System?

A. forloop.lastitem
B.  forloop.counter
C. forloop.firstitem
D. forloop.reverse

56.Django Comments framework is deprecated, since the 1.5 version.

A. TRUE
B. FALSE
C. Can be true or false
D. Can not say

 57.Which of these is not a valid method or approach to perform URL resolution?

A. Using Template {{ url : }} in template
B. Using reverse() in View Functions
C. Using get_absolute_url()
D. None of the above 

58.View response can be the ?

A. HTML contents
B. 404 error
C. XML document
D. All of the above



  












Question No Answer
1 B
2 A
3 C
4 A
5 B
6 D
7 B
8 C
9 B
10 C
11 A
12 C
13 A
14 A
15 B
16 D
17 E
18 D
19 D
20 D
21 D
22 B
23 B
24 A
25 B
26 D
27 D
28 D
29 D
30 A
31 C
32 A
33 D
34 D
35 C
36 B
37 D
38 D
39 A
40 B
41 D
42 A
43 A
44 C
45 D
46 C
47 C
48 D
49 A
50 D
  



If you any have doubt,suggestion regarding this post or website then feel free to share with us.
 
If you have learned something new from this post then share this post with your family and
friends.
 
Happy Learning :)😎  


Post a Comment

Previous Post Next Post