Django – Web Framework Interview Question-Answer Part – 2

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(‘’)),
#in entertain/urls/
urlpatterns = [

The would correspond to the URL.

       A. /2018/music/

       B. /2018/music/history/

       C. /music/2018

       D. /music/history/2018

Ans : /2018/music/history/

Leave a Comment

Your email address will not be published. Required fields are marked *