Question#1 Sessions are __________.
a) File-based
b) Cookie-based
c) cached
d) Database-backend
e) All the options
Answer- All the options
Question#2 Identify the incorrect middleware hook.
a) process_template_response()
b) template_view()
c) process_exception()
d) process_view()
Answer- template_view()
Question#3 urlpatterns should be a python list of ______ instances.
a) re_path()
b) path()
c) both options
d) None of the options
Answer- both options
Question#4 Identify the incorrect path argument.
a) view
b) route
c) model
d) name
Answer- model
Question#5 By default, Django serializes session using ________.
a) json
b) pickle
c) both options
d) None of the options
Answer- json
Question#6 Which is a valid path converter?
a) slug
b) int
c) str
d) uuid
e) str and int
f) All the options
Answer- All the options
Question#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
Answer- All the options
Question#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
Answer- django.views.decorators.cache
Question#9 HttpRequest object is automatically created by Django when a page is refreshed.
a) True
b) False
Answer- True
Question#10 Mixins are a form of multiple inheritance where behaviors and attributes of multiple parent classes can be combined.
a) True
b) False
Answer- True
Question#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
Answer- All the options
Question#12 Which view can be used to show the detail of an object?
a) ListView
b) DetailView
c) View
d) TemplateView
Answer- DetailView
Question#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()
Answer- get_list_or_404()
Question#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()
Answer- http_forbidden()
Question#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
Answer- django.views.decorators.http
Question#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
Answer- All the options
Question#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
Answer- All the options
Question#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
Answer- True
Question#19 You cannot have spaces or punctuation characters in variable names.
a) True
b) False
Answer- True
Question#20 Which option does Django templates accept?
a) context_processors
b) autoescape
c) libraries
d) loaders
e) All the options
Answer- All the options
Question#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
Answer- It should be the last template tag in the template
Question#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
Answer- DIRS
Question#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
Answer- All the options
Question#24 filesizeformat filter in a template, provides the output in a human readable format.
a) True
b) False
Answer- True
Django – REST Framework Questions
Question#1 If you are supporting writable nested representations, you need to add __________ method for saving multiple objects.
a) .create() and .update()
b) Nothing. Serializers are default writable
c) .update()
d) .create()
Answer:-.create() and .update()
Question#2 Identify the core arguments of each serializer field class constructor.
a) allow_null
b) read_only
c) write_only
d) required
e) All the options
Answer:-All the options
Question#3 Serializer validation errors return __________ reponse by default.
a) HTTP 400 Bad Request
b) HTTP 500 Internal Server Error
c) HTTP 404 Not Found
d) None of the options
e) All the options
Answer:-HTTP 400 Bad Request
Question#4 Serializer fields are referred by using ________.
a) model.FieldName
b) serializers.<FieldName>
c) FieldName
d) All the options
Answer:-serializers.<FieldName>
Question#5 To get multiple objects using ListSerializer, ________ option should be used.
a) list=True
b) many=True
c) include(list)
d) include(many)
Answer:-many=True
Question#6 Individual fields on a serializer can include validators, by declaring them on the field instance. Is this statement true?
a) True
b) False
Answer:-True
Question#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?
a) True
b) False
Answer:-True
Question#8 request.data handles arbitrary data and works for _____ HTTP methods.
a) POST
b) PUT
c) PATCH
d) All the options
Answer:-All the options
Question#9 If a client sends malformed content, it will raise a ParseError. What catches the error and responds with a 400 Bad Request.
a) APIView Class
b) @api_view decorator and APIView class
c) @api_view decorator
d) web browser
e) custom function
Answer:-@api_view decorator and APIView class
Question#10 To render the serialized data of the response into the final response, the __________ method is called.
a) .render()
b) .data
c) Response
d) .content_type
Answer:-.render()
Question#11 When you want an interface for returning content-negotiated Web API responses, you go for
a) HttpResponse
b) StreamingHttpResponse
c) Response
d) All the options
Answer:-Response
Question#12 Identify the correct status code which indicates that the server is incapable of performing a request and errors out.
a) HTTP_500_INTERNAL_SERVER_ERROR
b) HTTP_503_SERVICE_UNAVAILABLE
c) HTTP_502_BAD_GATEWAY
d) HTTP_501_not_IMPLEMENTED
e) All the options
Answer:-All the options
Question#13 Identify the concrete view which extends the GenericAPIView and ListModelMixin
a) DestroyAPIView
b) RetrieveAPIView
c) CreateAPIView
d) ListAPIView
Answer:-ListAPIView
Question#14 APIView uses HTTPRequest and HTTPResponse instances. Is this statement correct?
a) True
b) False
Answer:-False
Question#15 Request objects treat JSON data and other media types in same way as dealing with form data. Is this statement correct?
a) True
b) False
Answer:-True
Question#16 When you use @api_view based View, it uses default renderers, parsers and authentication classes. Is this statement correct?
a) True
b) False
Answer:-True
Question#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?
a) True
b) False
Answer:-True
Question#18 Which is not a view action
a) Retrieve
b) Create
c) List
d) Delete
Answer:-Delete
Question#19 Which class controls the pluggable aspects of API views
a) .renderer_classes
b) .permission_classes
c) .authentication_classes
d) All the options
Answer:-All the options
Question#20 Which is not an HTTP handler method
a) .get()
b) .put()
c) .list()
d) .delete()
e) .post()
Answer:-.list()
Question#21 The default @api_view implementation accepts only GET method and responds with _______ for other methods.
a) 406 Not Acceptable
b) 405 Method Not Allowed
c) 505 HTTP Version Not Supported
d) 400 Bad Request
Answer:-405 Method Not Allowed
Question#22 Oauth authentication scheme can be established using which external package
a) Django Oauth Toolkit
b) Django REST Framework Oauth
c) Django OAuth2 Consumer
d) All the options
Answer:-All the options
Question#23 Which statement is applicable for CSRF validation in REST Framework
a) support both session and non-session based authentication to the same views
b) not suitable for login views
c) only authenticated requests require CSRF tokens
d) anonymous requests may be sent without CSRF tokens
e) All the options
Answer:-All the options
Question#24 The authentication scheme that allows you to delegate authentication to your web server, which sets the REMOTE_USER environment variable is called ___________.
a) Token Authentication
b) Remote User Authentication
c) Basic Authentication
d) Session Authentication
Answer:-Remote User Authentication
Question#25 Relational fields when rendered in a browsable API display a maximum of _____ items.
a) 10000
b) 1000
c) 500
d) 100
Answer:-1000
Question#26 Relational fields represent model relationships. They can be applied to _______.
a) ForeignKey
b) Reverse Relationships
c) OnetoOneField
d) ManytoManyField
e) All the options
Answer:-All the options
Question#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?
a) True
b) False
Answer:-True
Question#28 When permission classes are set through class attribute or decorators, it ignores the default settings in the settings.py file. Is this correct
a) True
b) False
Answer:-False
Question#29 HyperlinkedModelSerializer includes id field by default
a) True
b) False
Answer:-False
Question#30 To use Hyperlinked API, it is essential to name the URL pattern. Is this correct?
a) True
b) False
Answer:-False
Question#31 Serializer Relationships can be represented using
a) hyperlinking between entitities
b) default string representation of the related entity
c) unique identifying slug field on a related entity
d) primary keys
e) All the options
Answer:-All the options
Question#32 What adds login and logout views for a browsable API,
a) urlpatterns += [
url(r’^api-auth/’, include(‘rest_framework.loginViews’)),
]
b) urlpatterns += [
url(r’^api-auth/’, include(‘rest_framework.login.urls’)),
]
c) urlpatterns += [
url(r’^api-auth/’, include(‘rest_framework.urls’)),
]
d) urlpatterns += [
url(r’^api-auth/’, include(‘rest_framework.login’)),
]
Answer:-urlpatterns += [
url(r’^api-auth/’, include(‘rest_framework.urls’)),
]