Top 50 Django REST Framework Interview Questions & Answers

Django is an MVT web framework that is used to build web applications. The huge Django web-framework comes with so many “batteries included” that developers often get amazed as to how everything manages to work together.

The principle behind adding so many batteries is to have common web functionalities in the framework itself instead of adding latter as a separate library.

This framework uses a famous tag line:The web framework for perfectionists with deadlines.

By using Django, we can build web applications in very less time. Django is designed in such a manner that it handles much of configure things automatically, so we can focus on application development only.

Django Multiple Choice Questions and Answers

Question#1 If you are supporting writable nested representations, you need to add __ method for saving multiple objects.


i) .create() and .update()

ii) Nothing. Serializers are default writable

iii) .update()

iv) .create()

Answer: – .create() and .update()

Question#2 Identify the core arguments of each serializer field class constructor.

i) allow_null

ii) read_only

iii) write_only

iv) required

v) All the options

Answer: – All the options

Question#3 Serializer validation errors return __ reponse by default.

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

Question#4 Serializer fields are referred by using __.

i) model.FieldName

ii) serializers.

iii) FieldName

iv) All the options

Answer: – serializers.

Question#5 To get multiple objects using ListSerializer, __ option should be used.

i) list=True

ii) many=True

iii) include(list)

iv) 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?

i) True

ii) 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?

i) True

ii) False

Answer: – True

Question#8 request.data handles arbitrary data and works for _ HTTP methods.

i) POST

ii) PUT

iii) PATCH

iv) 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.

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

Question#10 To render the serialized data of the response into the final response, the __ method is called.

i) .render()

ii) .data

iii) Response

iv) .content_type

Answer: – .render()

Question#11 When you want an interface for returning content-negotiated Web API responses, you go for

i) HttpResponse

ii) StreamingHttpResponse

iii) Response

iv) 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.

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

Question#13 Identify the concrete view which extends the GenericAPIView and ListModelMixin

i) DestroyAPIView

ii) RetrieveAPIView

iii) CreateAPIView

iv) ListAPIView

Answer: – ListAPIView

Question#14 APIView uses HTTPRequest and HTTPResponse instances. Is this statement correct?

i) True

ii) 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?

i) True

ii) False

Answer: – True

Question#16 When you use @api_view based View, it uses default renderers, parsers and authentication classes. Is this statement correct?

i) True

ii) 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?

i) True

ii) False

Answer: – True

Question#18 Which is not a view action

i) Retrieve

ii) Create

iii) List

iv) Delete

Answer: – Delete

Question#19 Which class controls the pluggable aspects of API views

i) .renderer_classes

ii) .permission_classes

iii) .authentication_classes

iv) All the options

Answer: – All the options

Question#20 Which is not an HTTP handler method

i) .get()

ii) .put()

iii) .list()

iv) .delete()

v) .post()

Answer: – .list()

Question#21 The default @api_view implementation accepts only GET method and responds with _ for other methods.

i) 406 Not Acceptable

ii) 405 Method Not Allowed

iii) 505 HTTP Version Not Supported

iv) 400 Bad Request

Answer: – 405 Method Not Allowed

Question#22 Oauth authentication scheme can be established using which external package

i) Django Oauth Toolkit

ii) Django REST Framework Oauth

iii) Django OAuth2 Consumer

iv) All the options

Answer: – All the options

Question#23 Which statement is applicable for CSRF validation in REST Framework

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

Question#24 The authentication scheme that allows you to delegate authentication to your web server, which sets the REMOTE_USER environment variable is called _.

i) Token Authentication

ii) Remote User Authentication

iii) Basic Authentication

iv) Session Authentication

Answer: – Remote User Authentication

Question#25 Relational fields when rendered in a browsable API display a maximum of _ items.

i) 10000

ii) 1000

iii) 500

iv) 100

Answer: – 1000

Question#46 Relational fields represent model relationships. They can be applied to _.

i) ForeignKey

ii) Reverse Relationships

iii) OnetoOneField

iv) ManytoManyField

v) All the options

Answer: – All the options

Question#47 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?

i) True

ii) False

Answer: – True

Question#48 When permission classes are set through class attribute or decorators, it ignores the default settings in the settings.py file. Is this correct

i) True

ii) False

Answer: – False

Question#49 HyperlinkedModelSerializer includes id field by default

i) True

ii) False

Answer: – False

Question#50 To use Hyperlinked API, it is essential to name the URL pattern. Is this correct?

i) True

ii) False

Answer: – False

Question#51 Serializer Relationships can be represented using

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

Question#52 What adds login and logout views for a browsable API,

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 Version History

VersionDateDescription
0.9016 Nov 2005
0.9111 Jan 2006magic removal
0.9623 Mar 2007newforms, testing tools
1.03 Sep 2008API stability, decoupled admin, unicode
1.129 Jul 2009Aggregates, transaction based tests
1.217 May 2010Multiple db connections, CSRF, model validation
1.323 Mar 2011Timezones, in browser testing, app templates.
1.526 Feb 2013Python 3 Support, configurable user model
1.66 Nov 2013Dedicated to Malcolm Tredinnick, db transaction management, connection pooling.
1.72 Sep 2014Migrations, application loading and configuration.
1.8 LTS2 Sep 2014Migrations, application loading and configuration.
1.8 LTS1 Apr 2015Native support for multiple template engines.Supported until at least April 2018
1.91 Dec 2015Automatic password validation. New styling for admin interface.
1.101 Aug 2016Full text search for PostgreSQL. New-style middleware.
1.11 LTS1.11 LTSLast version to support Python 2.7.Supported until at least April 2020
2.0Dec 2017First Python 3-only release, Simplified URL routing syntax, Mobile friendly admin.
source: https://www.javatpoint.com/

Difference between Django and PHP

ParameterDjangoPHP
OverviewDjango is a popular web framework written in the Python programming language. It is open-source and used to build rich web applications.PHP is a Hypertext Preprocessor scripting language that is used to build dynamic web applications.
SyntaxDjango can be run easily using the cmd prompt on both Window and Linux. We can navigate the project location through the commands.The basic syntax of PHP helps to learn PHP well. Escaping to PHP, the PHP parsing engines need differentiate between normal code and PHP.
Database SupportIt provides built-in support for most of the popular databases.It doesn’t provide the facility to choose between databases.
DRY ParadigmIt follows the DRY (Don’t Repeat Yourself) paradigm, which cut-off the development time and leading to efficient code.In PHP, we need to define everything.
Security StandardsIt covers all the security loopholes of PHP.It can build a secure website but require experienced and skilled developer.
File UploadingDjango allows the users to upload the files. To upload the image, we need to install the Python image library.In PHP, files are uploaded temporarily and will be redirected to target destinations by a PHP script.
DocumentationDjango has very nicely structured documentation which motivates to learn to newbies.PHP is also well-written but not as Django.
ExtensionExtension of Django file is .py.Extension of PHP file is .php.
PopularityDjango is used by many tech-giants like Google, Facebook, Instagram, etc.Websites like Wikipedia, Tumblr, Yahoo run on PHP

Comparison between Django and PHP

Following is the comparison of Django and PHP performance.

Environment Setup

Django is a Python framework; hence Python must be installed to work with Django. The Python version should be 2.6.5 or a higher. After that, we need to run the pip install Django command to install Django.

PHP includes three important components that should be installed in the system. There are –

  • Web Server
  • Database
  • PHP Parser

Before installing PHP Parser, check if this link is updated http://127.0.0.1/info.php if this link runs successfully, then PHP and Web server and installed successfully.

Advantages of Django

  • Django reduces the development time by adding add functionalities. Developer can develop the project in shorten-time.
  • Django is a scalable framework and allows scaling seamlessly and keeping up with growing needs.
  • It protects the Django website from common attacks such as cross-site request forgery, SQL injections, clickjacking, etc.
  • Django supports the rapid changes during development.
  • Django is a machine learning-friendly framework because it provides computational and statistical capabilities.

Advantages of PHP

The following are the important advantages of the PHP scripting language.

  • It comes with pre-written, ready-to-use codes that save time for development.
  • It is supported by various operating systems, including Linux, UNIX, Solaris, macOS, and Windows.
  • PHP is easy to learn, and it is quite similar to the C programming language.
  • It offers a high speed that boosts user engagement and SEO ranking by loading web pages faster.

Disadvantages of Django

  • Django is not suitable for smaller projects. It is a battery-included framework that occupying a lot of bandwidth and server.
  • It can handle only one request at a time.
  • It is also considered to be monolithic. It slows down the framework evaluation.

Disadvantages of PHP

  • The developer requires an additional interpreter program for the interpretation of codes in computer-friendly language.
  • The main concern of PHP is the lack of uniformity in the structural patterns that increase the cost of hiring new human resources.
  • Developers need to install third-party tools to speed up the user experience, which slows down the website.

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