0 votes
in Django by

Read Django Interview Questions and Answers with Explanation on below :

  • python django interview questions and answers
  • django test questions
  • django drf interview questions
  • python django interview questions and answers pdf
  • django interview questions for experienced person
  • django interview questions github
  • django interview questions for 3 years experienced
  • django important topics
  • Django – REST Framework Interview Questions & Answers

2 Answers

0 votes
by
edited by

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/

0 votes
by

Django Object Relational Mapper Interview Questions and Answers

Q.1 Choose the correct option to create an app ‘myapp’.

a) python manage.py start myapp

b) python manage.py startproject myapp

c) python manage.py startapp myapp

d) python manage.py myapp

Ans : python manage.py startapp myapp

Q.2 A Django app will contain _____.

a) views.py

b) tests.py

c) apps.py

d) models.py

e) All the options

Ans : All the options

Q.3 Choose the correct option to create a project myworld using the Django-admin command.

a) $ django-admin createproject myworld

b) $ django-admin create myworld

c) $ django-admin startproject myworld

d) $ django-admin start myworld

Ans : $ django-admin startproject myworld

Q.4 Select the incorrect statement.

a) A project can have multiple apps

b) A project can have a single application

c) One app can be in multiple projects

d) None of the options

Ans : A project can have multiple apps

Q.5 Which setting can be used while adding a new Django app?

a) DYNAMIC_APPS

b) ADD_APPS

c) INSTALLED_APPS

d) CREATE_APPS

Ans : INSTALLED_APPS

Q.6 Select the incorrect statement: Django ORM.

a) Auto generates primary keys

b) Efficient for simple and medium databases

c) Autocommit transactions

d) Supports SQLite only

Ans : Supports SQLite only

Q.7 Object-relational Mapper (ORM) is a code library to automate the data transfer between _______.

a) Databases and Objects

b) Objects and Arrays

c) Databases and Arrays

d) Relational DB and Objects

Ans : Relational DB and Objects

Q.8 Identify the ORM most used for Flask Web Framework.

a) peewee

b) SQLAlchemy

c) Hibernate

d) Django’s ORM

Ans : SQLAlchemy

Q.9 What is/are applicable for Django ORM?

a) Shifting complexity from the database into the application code

b) Potential for reduced performance

c) Impedance mismatch

d) All the options

Ans : All the options

Q.10 id- is the auto assigned primary key by Django with the datatype.

a) models.FloatField()

b) models.TextField()

c) models.AutoField()

d) models.IntegerField()

Ans : models.AutoField()

Q.11 What are the different ways of connecting multiple models relationship?

a) One-to-one

b) Many-to-one

c) Many-to-many

d) All the options

Ans : All the options

Q.12 To rename the Manager for a given class, what attribute type can be used in models.Manager() on that model?

a) objects

b) Customer

c) filter

d) class

Ans : class

Q.13 A Django model is a Python class that subclasses _________.

a) djangodb.models.Model

b) django.db.model.Models

c) djangodb.model.Models

d) django.db.models.Model

Ans : django.db.models.Model

Q.14 When choosing field names for the model, it should not conflict with the model API. The field name should not be _________.

a) clean

b) clean, save and delete

c) save and delete

d) delete

e) save

f) clean and save

Ans : clean, save and delete

Q.15 What exception is an attribute of each model class?

a) ClassDoesnotExist

b) AttributeDoesnotExist

c) ObjectDoesnotExist

d) DoesnotExist

Ans : DoesnotExist

Q.16 What can be used to provide custom model validation and to modify attributes on the model like changing the value on a field upon a conditional check?

a) Model.full_clean()

b) Model.clean()

c) Model.validate_unique(exclude=None)

d) Model.clean_fields(exclude=None)

Ans : Model.clean()

Q.17 What can be used to validate all model fields, if any field is to be exempted from validation? Provide it in the exclude parameter.

a) Model.clean()

b) Model.clean_fields(exclude=None)

c) Model.full_clean()

d) Model.validate_unique(exclude=None)

Ans : Model.clean_fields(exclude=None)

Q.18 What can be used to validate all unique constraints on the model instead of individual field values?

a) Model.clean()

b) Model.clean_fields(exclude=None)

c) Model.full_clean()

d) Model.validate_unique(exclude=None)

Ans : Model.validate_unique(exclude=None)

Q.19 When an object is saved, Django _____________.

a) emits a pre save signal

b) emit a post save signal

c) prepares data for the database

d) preprocesses the data

e) inserts data into database

f) all the options

Ans : all the options

Q.20 Select the incorrect statement about A QuerySet.

a) Can have filters to obtain different query results

b) Is a collection of database objects

c) Incomparable to a database select operation

d) Can be operated on a model

Ans : Incomparable to a database select operation

Q.21 Select the incorrect statement: QuerySet API are classified as _________.

a) Methods that return new QuerySets

b) Field Lookups

c) Methods that do not return QuerySets

d) Methods that return new querysets’ AND ‘field lookups’ AND ‘aggregation functions’

e) Aggregation funcions

f) all the options

Ans : all the options

Q.22 Django is loaded with a database-abstraction API to ______.

a) update and delete objects

b) create objects

c) retrieve objects

d) all the options

Ans : all the options

Q.23 Data migrations _________.

a) alter data

b) use RunPython operation that takes a callable as argument

c) custom written unlike schema migrations

d) all the options

Ans : all the options

Q.24 Table names in databases are created by default with app_classname.

a) True

b) False

Ans : True

Q.25 exclude(**kwargs) – Returns QuerySet containing objects matching given lookup parameters.

a) True

b) False

Ans : False

Related questions

0 votes
asked Jun 29, 2022 in Django by sharadyadav1986
0 votes
asked Jun 28, 2022 in Django by Robin
...