Ques:-1 If you are supporting writable nested representations, you need to add __________ method for saving multiple objects.
Select the correct option from below
i) .create() and .update()
ii) Nothing. Serializers are default writable
iii) .update()
iv) .create()
Answer:- .create() and .update()
Ques:-2 Identify the core arguments of each serializer field class constructor.
Select the correct option from below
i) allow_null
ii) read_only
iii) write_only
iv) required
v) All the options
Answer:- All the options
Ques:-3 Serializer validation errors return __________ reponse by default.
Select the correct option from below
i) HTTP 400 Bad Request
ii) HTTP 500 Internal Server Error
iii) HTTP 404 Not Found
iv) None of the options
v) All the options
Answer:- HTTP 400 Bad Request
Ques:-4 Serializer fields are referred by using ________.
Select the correct option from below
i) model.FieldName
ii) serializers.<FieldName>
iii) FieldName
iv) All the options
Answer:- serializers.<FieldName>
Ques:-5 To get multiple objects using ListSerializer, ________ option should be used.
Select the correct option from below
i) list=True
ii) many=True
iii) include(list)
iv) include(many)
Answer:- many=True
Ques:-6 Individual fields on a serializer can include validators, by declaring them on the field instance. Is this statement true?
Select the correct option from below
i) True
ii) False
Answer:- True
Ques:-7 Since the API chooses the content type of the response based on the client request, it will return an HTML-formatted representation of the resource in a web-browsable form. Is this statement correct?
Select the correct option from below
i) True
ii) False
Answer:- True
Ques:-8 request.data handles arbitrary data and works for _____ HTTP methods.
Select the correct option from below
i) POST
ii) PUT
iii) PATCH
iv) All the options
Answer:- All the options
Ques:-9 If a client sends malformed content, it will raise a ParseError. What catches the error and responds with a 400 Bad Request.
Select the correct option from below
i) APIView Class
ii) @api_view decorator and APIView class
iii) @api_view decorator
iv) web browser
v) custom function
Answer:- @api_view decorator and APIView class
Ques:-10 To render the serialized data of the response into the final response, the __________ method is called.
Select the correct option from below
i) .render()
ii) .data
iii) Response
iv) .content_type
Answer:- .render()
Ques:-11 When you want an interface for returning content-negotiated Web API responses, you go for
Select the correct option from below
i) HttpResponse
ii) StreamingHttpResponse
iii) Response
iv) All the options
Answer:- Response
Ques:-12 Identify the correct status code which indicates that the server is incapable of performing a request and errors out.
Select the correct option from below
i) HTTP_500_INTERNAL_SERVER_ERROR
ii) HTTP_503_SERVICE_UNAVAILABLE
iii) HTTP_502_BAD_GATEWAY
iv) HTTP_501_not_IMPLEMENTED
v) All the options
Answer:- All the options
Ques:-13 Identify the concrete view which extends the GenericAPIView and ListModelMixin
Select the correct option from below
i) DestroyAPIView
ii) RetrieveAPIView
iii) CreateAPIView
iv) ListAPIView
Answer:- ListAPIView
Ques:-14 APIView uses HTTPRequest and HTTPResponse instances. Is this statement correct?
Select the correct option from below
i) True
ii) False
Answer:- False
Ques:-15 Request objects treat JSON data and other media types in same way as dealing with form data. Is this statement correct?
Select the correct option from below
i) True
ii) False
Answer:- True
Ques:-16 When you use @api_view based View, it uses default renderers, parsers and authentication classes. Is this statement correct?
Select the correct option from below
i) True
ii) False
Answer:- True
Ques:-17 Authentication by itself won’t allow or disallow an incoming request, it simply identifies the credentials that the request was made with. Is this correct?
Select the correct option from below
i) True
ii) False
Answer:- True
Ques:-18 Which is not a view action
Select the correct option from below
i) Retrieve
ii) Create
iii) List
iv) Delete
Answer:- Delete
Ques:-19 Which class controls the pluggable aspects of API views
Select the correct option from below
i) .renderer_classes
ii) .permission_classes
iii) .authentication_classes
iv) All the options
Answer:- All the options
Ques:-20 Which is not an HTTP handler method
Select the correct option from below
i) .get()
ii) .put()
iii) .list()
iv) .delete()
v) .post()
Answer:- .list()
Ques:-21 The default @api_view implementation accepts only GET method and responds with _______ for other methods.
Select the correct option from below
i) 406 Not Acceptable
ii) 405 Method Not Allowed
iii) 505 HTTP Version Not Supported
iv) 400 Bad Request
Answer:- 405 Method Not Allowed
Ques:-22 Oauth authentication scheme can be established using which external package
Select the correct option from below
i) Django Oauth Toolkit
ii) Django REST Framework Oauth
iii) Django OAuth2 Consumer
iv) All the options
Answer:- All the options
Ques:-23 Which statement is applicable for CSRF validation in REST Framework
Select the correct option from below
i) support both session and non-session based authentication to the same views
ii) not suitable for login views
iii) only authenticated requests require CSRF tokens
iv) anonymous requests may be sent without CSRF tokens
v) All the options
Answer:- All the options
Ques:-24 The authentication scheme that allows you to delegate authentication to your web server, which sets the REMOTE_USER environment variable is called ___________.
Select the correct option from below
i) Token Authentication
ii) Remote User Authentication
iii) Basic Authentication
iv) Session Authentication
Answer:- Remote User Authentication
Ques:-25 Relational fields when rendered in a browsable API display a maximum of _____ items.
Select the correct option from below
i) 10000
ii) 1000
iii) 500
iv) 100
Answer:- 1000
Ques:-26 Relational fields represent model relationships. They can be applied to _______.
Select the correct option from below
i) ForeignKey
ii) Reverse Relationships
iii) OnetoOneField
iv) ManytoManyField
v) All the options
Answer:- All the options
Ques:-27 Authentication by itself won’t allow or disallow an incoming request, it simply identifies the credentials that the request was made with. Is this correct?
Select the correct option from below
i) True
ii) False
Answer:- True
Ques:-28 When permission classes are set through class attribute or decorators, it ignores the default settings in the settings.py file. Is this correct
Select the correct option from below
i) True
ii) False
Answer:- False
Ques:-29 HyperlinkedModelSerializer includes id field by default
Select the correct option from below
i) True
ii) False
Answer:- False
Ques:-30 To use Hyperlinked API, it is essential to name the URL pattern. Is this correct?
Select the correct option from below
i) True
ii) False
Answer:- False
Ques:-31 Serializer Relationships can be represented using
Select the correct option from below
i) hyperlinking between entitities
ii) default string representation of the related entity
iii) unique identifying slug field on a related entity
iv) primary keys
v) All the options
Answer:- All the options
Ques:-32 What adds login and logout views for a browsable API,
Select the correct option from below
i) urlpatterns += [
url(r’^api-auth/’, include(‘rest_framework.loginViews’)),
]
ii) urlpatterns += [
url(r’^api-auth/’, include(‘rest_framework.login.urls’)),
]
iii) urlpatterns += [
url(r’^api-auth/’, include(‘rest_framework.urls’)),
]
iv) urlpatterns += [
url(r’^api-auth/’, include(‘rest_framework.login’)),
]
Answer:- urlpatterns += [
url(r’^api-auth/’, include(‘rest_framework.urls’)),
]
Django Web Framework Interview Questions and Answers Part – II
Question#1 Identify the invalid form field attributes.
a) {{ field.errors }}
b) {{ field.value }}
c) {{ field.invalid }}
d) {{ field.help_text }}
Answer:- {{ field.invalid }}
Question#2 To declare the initial value of form fields at runtime, use ________.
a) Form.first
b) Form.initial
c) Form.start
d) Form.index
Answer:- Form.initial
Question#3 The clean() method on a Field subclass is responsible for running ________.
a) to_python()
b) validate()
c) run_validators()
d) All the options
Answer:- All the options
Question#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
Answer:- Formset
Question#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
Answer:- Validation Error
Question#6 A Form instance is either bound to a set of data or unbound.
a) True
b) False
Answer:- True
Question#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
Answer:- The form renders as HTML
Question#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 %}
Answer:- {% load %}
Question#9 Which is not a Generic Editing View?
a) UpdateView
b) DetailView
c) DeleteView
d) CreateView
Answer:- DetailView
Question#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” %}
Answer:- {% include “form_sample.html” %}
Question#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
Answer:- views,year
Question#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’] = {}
Answer:- request.session[‘course’] = ‘django’
Question#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
Answer:- 3.86 million
Question#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
Answer:- All the options
Question#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
Answer:- handler403
Question#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()
Answer:- get_list_or_404()
Question#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
Answer:- django.views.decorators.gzip
Question#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
Answer:- get_template()
Question#19 The default middleware included in the settings is ___________.
a) CommonMiddleware
b) CsrfViewMiddleware
c) SessionMiddleware
d) AuthenticationMiddleware
e) All the options
Answer:- CommonMiddleware
Question#20 Which templating language is supported default by Django?
a) mustache
b) jinja
c) HandlebarsJs
d) Jade Templating
Answer:- jinja
Question#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
Answer:- True
Question#22 Which HttpResponse can be used to send a JSON encoded response?
a) HttpResponse objects
b) SteamingHttpResponse objects
c) FileResponse objects
d) JsonResponse objects
Answer:- JsonResponse objects
Question#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
Answer:- Toyota
Question#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
Answer:- Safe Strings
Question#25 Which is a framework of hooks into Django’s request, response processing?
a) Template
b) Form
c) View
d) Middleware
Answer:- Middleware
Question#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
Answer:- /2018/music/history/