Django – Web Framework Interview Question-Answer

Django – Web Framework

Q.1 Identify the invalid form field attributes.

       A. {{ field.errors }}

       B. {{ field.value }}

       C. {{ field.invalid }}

       D. {{ field.help_text }}

Ans : {{ field.invalid }}


Q.2 To declare the initial value of form fields at runtime, use ________.

       A. Form.first

       B. Form.initial

       C. Form.start

       D. Form.index

Ans : Form.initial


Q.3 The clean() method on a Field subclass is responsible for running ________.

       A. to_python()

       B. validate()

       C. run_validators()

       D. All the options

Ans : All the options


Q.4 A ______ is a layer of abstraction to work with multiple forms on the same page.

       A. InlineForm

       B. Formset

       C. ModelForm

       D. All the options

Ans : Formset

Q.5 What is the output of the following code?
>>> from Django import forms
>>> f = forms.CharField()
>>> f.clean(”)

       A. True

       B. ’’

       C. None

       D. Validation Error

Ans : Validation Error


Q.6 A Form instance is either bound to a set of data or unbound.

       A. True

       B. False

Ans : True


Q.7 Consider the following code where f is a Form object
>>> f = ContactForm()
>>> print(f)

What is the output?

       A. An error is displayed

       B. The form is not rendered

       C. The form renders as HTML

       D. None of the options

Ans : The form renders as HTML


Q.8 When you define custom tags and filters using python to make them available to templates, use __________.

       A. {% start %}

       B. {% include %}

       C. {% define %}

       D. {% load %}

Ans : {% load %}

Q.9 Which is not a Generic Editing View?

       A. UpdateView

       B. DetailView

       C. DeleteView

       D. CreateView

Ans : DetailView


Q.10 To reuse a form template form_sample.html, the correct approach is _____.

       A. {% reuse “form_sample.html” %}

       B. {% “form_sample.html” %}

       C. {% include “form_sample.html” %}

       D. {% use “form_sample.html” %}

Ans : {% include “form_sample.html” %}


Q.11 Consider a URL pattern

urlpatterns = [
  path(‘category/2018/’, views.handle_2018),
  path(‘category//’, views.year),]

The URL /category/2018 will match ___________.

       A. views,year

       B. views.handle_2018

       C. both options

       D. None of the options

Ans : views,year


Q.12 Identify the incorrect session modification.

       A. request.session[‘course’] = ‘django’

       B. del request.session[‘course’]

       C. request.session[‘course’][‘name’] = ‘python’

       D. request.session[‘course’] = {}

Ans : request.session[‘course’] = ‘django’

Q.13 With {% load humanize %} and the filter intword is used, the value for 3860000 becomes?

       A. 3,86 million

       B. 3.86 million

       C. 3,860,000

       D. 0.0386 billion

Ans : 3.86 million


Q.14 Which filter is available if {% load humanize %} is used in template?

       A. naturaltime

       B. naturalday

       C. apnumber

       D. intcomma

       E. intword

       F. All the options

Ans : All the options


Q.15 If you write customized error views, the permission_denied() view should be overridden by which handler?

       A. handler403

       B. handler404

       C. handler500

       D. handler400

Ans : handler403


Q.16 Which function calls get() on a given model manager, raises Http404 exception if the resulting object is empty?

       A. render()

B. render_to_response()

       C. get_object_or_404()

       D. get_list_or_404()

Ans : get_list_or_404()


Q.17 Which view decorator module can be used to control content compression on a per-view basis?

       A. django.views.decorators.gzip

       B. django.views.decorators.vary

       C. django.views.decorators.cache

       D. django.views.decorators.http

Ans : django.views.decorators.gzip


Q.18 To create a template, which factory method can be called _________.

       A. ABCDfrom_string()/p>

       B. select_template()

       C. get_template()

       D. All the options

Ans : get_template()


Q.19 The default middleware included in the settings is ___________.

       A. CommonMiddleware

       B. CsrfViewMiddleware

       C. SessionMiddleware

       D. AuthenticationMiddleware

       E. All the options

Ans : CommonMiddleware


Q.20 Which templating language is supported default by Django?

       A. mustache

       B. jinja

       C. HandlebarsJs

       D. Jade Templating

Ans : jinja


Q.21 What is the output of the following code?
>>>from Django import forms
>>> f = forms.CharField(required=False)
>>> f.clean(”)

       A. Validation Error

       B. None

       C. ’’

       D. True

Ans : True

Q.22 Which HttpResponse can be used to send a JSON encoded response?

       A. HttpResponse objects

       B. SteamingHttpResponse objects

       C. FileResponse objects

       D. JsonResponse objects

Ans : JsonResponse objects


Q.23 What is the output of the following code?
>>> t = Template(“The car you are searching for is {{ cars.1 }}.”)
>>> c = Context({“cars”: [“Nissan”, “Toyota”, “Honda”]})
>>> t.render(c)

       A. incorrect syntax

       B. Nissan

       C. Toyota

       D. Honda

Ans : Toyota


Q.24 Strings that have been marked safe from further escaping at output time are called __________.

       A. Typed Strings

       B. Safe Strings

       C. Secure Strings

       D. Raw Strings

Ans : Safe Strings


Q.25 Which is a framework of hooks into Django’s request, response processing?

       A. Template

       B. Form

       C. View

       D. Middleware

Ans : Middleware


Q.26 Consider

urlpatterns = [
  path(‘/music/’, include(‘entertain.urls.music’)),
]
#in entertain/urls/music.py
urlpatterns = [
  path(”, views.music.index),
  path(‘history/’, views.music.history),
]

The views.music.history would correspond to the URL.

       A. /2018/music/

       B. /2018/music/history/

       C. /music/2018

       D. /music/history/2018

Ans : /2018/music/history/

Q.1 Sessions are __________.

       A. File-based

       B. Cookie-based

       C. cached

       D. Database-backend

       E. All the options

Ans : All the options


Q.2 Identify the incorrect middleware hook.

       A. process_template_response()

       B. template_view()

       C. process_exception()

       D. process_view()

Ans : template_view()


Q.3 urlpatterns should be a python list of ______ instances.

       A. re_path()

       B. path()

       C. both options

       D. None of the options

Ans : both options


Q.4 Identify the incorrect path argument.

       A. view

       B. route

       C. model

       D. name

Ans : model


Q.5 By default, Django serializes session using ________.

       A. json

       B. pickle

       C. both options

       D. None of the options

Ans : json


Q.6 Which is a valid path converter?

       A. slug

       B. int

       C. str

       D. uuid

       E. str and int

       F. All the options

Ans : All the options


Q.7 A custom path converter is a class that includes _______.

       A. regex string

       B. to_url(self,value) method

       C. to_python(self, value) method

       D. All the options

Ans : All the options


Q.8 Which view decorator module can be used to control server and client-side caching?

       A. django.views.decorators.cache

       B. django.views.decorators.vary

 C. django.views.decorators.http

       D. django.views.decorators.gzip

Ans : django.views.decorators.cache


Q.9 HttpRequest object is automatically created by Django when a page is refreshed.

       A. True

       B. False

Ans : True


Q.10 Mixins are a form of multiple inheritance where behaviors and attributes of multiple parent classes can be combined.

       A. True

       B. False

Ans : True


Q.11 Generic views ____________.

       A. Display list and detail pages for a single object

       B. Present date-based objects in year/month/day archive pages

       C. Allow users to create, update, and delete objects

       D. All the options

Ans : All the options


Q.12 Which view can be used to show the detail of an object?

       A. ListView

       B. DetailView

       C. View

       D. TemplateView

Ans : DetailView


Q.13 Which shortcut function returns the result of filter() on a given model manager cast to a list, raising Http404 if the resulting list is empty?

       A. get_list_or_404()

B. render()

       C. render_to_response()

       D. get_object_or_404()

Ans : get_list_or_404()


Q.14 There are many error views by default in Django. Identify the incorrect one.

       A. http_forbidden()

       B. bad_request()

       C. permission_denied()

       D. server_error()

       E. page_not_found()

Ans : http_forbidden()


Q.15 Which view decorator module can be used to restrict access to views based on the request method?

       A. django.views.decorators.gzip

       B. django.views.decorators.http

       C. django.views.decorators.cache

       D. django.views.decorators.vary

Ans : django.views.decorators.http


Q.16 Which filter is available if {% load humanize %} is used in template?

       A. intcomma

       B. intword

       C. apnumber

       D. naturalday

 E. naturaltime

       F. sdasd

       D. All the options

Ans : All the options


Q.17 When a template system encounters a dot, it tries _______.

       A. Dictionary lookup

       B. Numeric index lookup

       C. Attribute or method lookup

       D. All the options

Ans : All the options


Q.18 Since the template language doesn’t provide exception handling, any exception raised from a template filter will be exposed as a server error.

       A. True

       B. False

Ans : True


Q.19 You cannot have spaces or punctuation characters in variable names.

       A. True

       B. False

Ans : True


Q.20 Which option does Django templates accept?

       A. context_processors

       B. autoescape

       C. libraries

       D. loaders

       E. All the options

Ans : All the options


Q.21 When {% extends %} is used for inheriting a template?

       A. It can be used anywhere in the template

       B. It should be the first template tag in the template

       C. It should follow a {% base %} template tag in the template

       D. It should be the last template tag in the template

Ans : It should be the last template tag in the template


Q.22 Which template configuration defines a list of directories where the engine should look for template source files, in search order?

       A. OPTIONS

       B. APP_DIRS

 C. DIRS

       D. BACKEND

Ans : DIRS


Q.23 Which filter is available if {% load humanize %} is used in template?

       A. apnumber

       B. intcomma

       C. naturalday

       D. intword

       E. naturaltime

       F. All the options

Ans : All the options


Q.24 filesizeformat filter in a template, provides the output in a human readable format.

       A. True

       B. False

Ans : True

Click here to read more Blogs

Click here to read more technical Interview Questions and Answers

Click here to read more Technical Q&A

About Author


After years of Technical Work, I feel like an expert when it comes to Develop wordpress website. Check out How to Create a Wordpress Website in 5 Mins, and Earn Money Online Follow me on Facebook for all the latest updates.

Leave a Comment