Theoretical Question For Interview

1. What are signals in Django ?

Signal are inbuilt utility in Django. They allow to execute some piece of code based on some action or event is occurred in framework something like a new user register, on delete of a record.
Below is the list of some inbuilt signal in Django.

  • pre_save and post_save.
  • pre_delete and post_delete
  • pre_request and post_request
  • pre_request and post_request

2. What does Of Django Field Class types do?

Following points are specified by the Django Field Class type: –

  • It specifies the database column type.
  • It also specifies the default HTML widget which is availed while we render the form field.
  • The requirements of the minimal validation which is used in Django admin is also specified by the field class.

3. List type of inheritance supported in Django?

Django supports 3 types of inheritance. They are

  • Abstract base classes
  • Multi-table Inheritance
  • Proxy models

4. Name the features available in Django web framework?

Features available in Django web framework are:

  • Admin Interface (CRUD)
  • Templating
  • Form handling
  • Internationalization
  • Session, user management, role-based permissions
  • Object-relational mapping (ORM)
  • Testing Framework
  • Fantastic Documentation

5. Clarify the architecture of Django?

Django follows MVC -MVT architecture. MVT  stand for Model View Template design Pattern which is little bit different from MVC (Model View Controller ) Pattern.

6. How to get current page URI in Django template.

You can use {{ request.path }} and {{ request.get_full_path }} to get current page URI in Django template.

7. Explain mixins in Django.

mixin is a special kind of multiple inheritances in Python. There are two main situations where mixins are used:

  • You want to provide a lot of optional features for a class.
  • You want to use one particular feature in a lot of different classes.

Read More from

8. What is a context in Django?

In Django Context is a dictionary with variable names in the form of key and value like {varible1: 101, varible2: 102},when we pass this context to the template render method, {{ varible1 }} would be replaced with 101 and {{ varible2 }} with 102 in your template.

9. How to set/unset session in Django?

Setting Session in Django

request.session['key'] = 'value'

Unset Session in Django

del request.session['key']

10. How to check installed version of Django?

By running below command on Terminal.You can check installed version of Django Framework.

py -m django --version

11. When to use the iterator in Django ORM?

Iterators are used for traversing an object in Python which implements iterator protocol. It consists of two methods __iter__() and next().
In Django, a good use of iterator is when you are processing results that take up a large amount of available memory (lots of small objects or fewer large objects).
For more clarification please read when to use and when to not use iterator() in the Python Django ORM

12. What is recommended way to install Django?

Installing using pip is the recommended way to install Django Framework. Below are the steps to install official release of Django with pip

  • Install pip.
  • Configure virtualenv and virtualenvwrapper
  • Once virtual environment is created and activated, enter the command pip install Django to install Django

13. List some caching strategies that you know in Django!

Few caching strategies that are available in Django are as follows:

  • File system caching
  • In-memory caching
  • Using Memcached
  • Database caching

14. What constitutes Django templates?

Template can create formats like XML,HTML and CSV(which are text-based formats). In general terms template is a simple text file. It is made up of variables that will later be replaced by values after the template is evaluated and has tags which will control template’s logic.

17. What is some typical usage of middlewares in Django?

Middleware is a function that acts on or transforms a request/response before/after it passes through the view layer (e.g. adding the user object to the request)
Some usage of middlewares in Django is:

  • It can be used for Session management,
  • User authentication can be done with the help of this.
  • It helps in Cross-site request forgery protection
  • Content Gzipping, etc.

18. What is the usage of and It is a Django’s command line utility for administrative It is an automatically created file in each Django project. It is a thin wrapper around the It has the following usage:

  • It puts your project’s package on sys.path.
  • It sets the DJANGO_SETTING_MODULE environment variable to points to your project’s file.

19. Is Django free?

Yes, Django is free open source web framework for Python

20. Django is based on which design pattern.

Django closely follows the MVC (Model View Controller) design pattern, however, it does use its own logic in the implementation. Because the “C” is handled by the framework itself and most of the excitement in Django happens in models, templates, and views, Django is often referred to as an MTV framework. In the MTV development pattern:

  • M stands for “Model,” the data access layer. This layer contains anything and everything about the data: how to access it, how to validate it, which behaviors it has, and the relationships between the data.
  • T stands for “Template,” the presentation layer. This layer contains presentation-related decisions: how something should be displayed on a Web page or other type of document.
  • V stands for “View,” the business logic layer. This layer contains the logic that accesses the model and defers to the appropriate template(s). You can think of it as the bridge between models and templates.

Further reading

21. When and who create Django?

According to, Django was created in the fall of 2003, when the web programmers at the Lawrence Journal-World newspaper, Adrian Holovaty and Simon Willison, began using Python to build applications. It was released publicly under a BSD license in July 2005. The framework was named after guitarist Django Reinhardt.

22. List server requirement to install Django Framework.

As Django is Python Framework, in order to install Django Python is required.Django comes with an inbuilt lightweight web server that you can use for the testing purpose.If you are using Django on production Apache with mod_wsgi is required.

23. List the database backends supported by Django Framework?

Django officially supports four database backends, they are

  • PostgreSQL
  • MySQL
  • SQLite
  • Oracle

In addition to these, you can also use following 3rd parties

  • SAP SQL Anywhere
  • IBM DB2
  • Microsoft SQL Server
  • Firebird
  • ODBC

24. How to install the development version of Django

Follow the below steps to Install the development version of Django Framework.

  • Check out Django’s main development branch
$ git clone
  • Make sure that the Python interpreter can load Django’s code. The most convenient way to do this is to use virtualenv, virtualenvwrapper, and pip.
  • After setting up and activating the virtualenv, run the following command:
$ pip install -e django/


25. Where are Django migrations stored?

You can think Django Migrations as version control system for your database/Model. It keeps track of changes done in your application Models/Table like adding a field, deleting a model, etc. Migrations in Django are stored as an on-disk format, referred to here as “migration files”. These files are actually just normal Python files with an agreed-upon object layout, written in a declarative style. A basic migration file looks like this:

from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [('migrations', '0001_initial')]

    operations = [
        migrations.AddField('Author', 'rating', models.IntegerField(default=0)),

Further Reading

26. How a request is processed in Django?

In Django whenever a request is made by a user, it goes through the following steps:

  • Django determines the root URLconf module to use. Ordinarily, this is the value of the ROOT_URLCONF setting, but if the incoming HttpRequest object has a urlconf attribute (set by middleware), its value will be used in place of the ROOT_URLCONF setting.
  • Django loads that Python module and looks for the variable urlpatterns. This should be a Python list of django.urls.path() and/or django.urls.re_path() instances.
  • Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL.
  • Once one of the URL patterns matches, Django imports and calls the given view, which is a simple Python function (or a class-based view). The view gets passed the following arguments:
    • An instance of HttpRequest.
    • If the matched URL pattern returned no named groups, then the matches from the regular expression are provided as positional arguments.
    • The keyword arguments are made up of any named parts matched by the path expression, overridden by any arguments specified in the optional kwargs argument to django.urls.path() or django.urls.re_path().
    • If no URL pattern matches, or if an exception is raised during any point in this process, Django invokes an appropriate error-handling view.

27. When QuerySets are evaluated in Django?

In Django, a QuerySet can be evaluated in Iteration, Slicing, Pickling/Caching, repr(),len(), list() and bool().

28. List some popular websites built on Django framework?

Following are the list of top 10 websites built on Django framework.

  1. Instagram
  2. Disqus
  3. Bitbucket
  4. Mozilla Firefox
  5. Pinterest
  6. NASA
  7. Onion
  8. The Washington Post
  9. Eventbrite
  10. Mahalo

29. How to create an Constant in Django.

To create a constant in Django. Open your file and add a variable like MY_CONST = “MY_VALUE”.
To use this constant in your views simply import setting like “Import settings in” and use it as

32. What do you understand by Django?

Django is a free and open source web application framework, written in Python. Django is named after Django Reinhardt, Jazz guitarist from the 1930s to early 1950s who is one of the best guitarists of all time. Django was mainly developed to handle the intensive design of the newsroom. You can even build high-quality web applications using this. It adheres to the DRY principle and focuses completely on automating as much as possible.

33. Does Django Follow Architectural pattern?

Yes, Django follows Model-View-Controller (MVC) architectural pattern.

34. Is Django stable or not?

Of course, Django is stable. Most of the companies are using it.

35. Is Django a high level or low-level framework?

Django is a high-level Python’s web framework which was designed for rapid development and clean realistic design.

36. How does Django work?

Django can be broken into several components:

  • file: This file defines your data model by extending your single code line into full database tables and add a pre-built administration section to manage content.
  • file: It uses a habitual expression to confine URL patterns for processing.
  • file: It is the main part of Django. The actual processing happens in view.

37. What is the name of the Foundation which manages Django web framework?

Django web framework is managed and maintained by an independent and non-profit organization named Django Software Foundation (DSF).

38. What are the advantages of using Django for web development?

  • Auto-generated web admin is provided by Django to make website administration easy.
  • Pre-packaged API is also available for common user tasks.
  • Business logic can be separated from the HTML using this framework.
  • You can even divide the code modules into logical groups so as to make it flexible for changing.
  • Template system is being provided so as to define HTML template for your web page to avoid code duplication.

39. What is the process of creating a project in Django?

To start a project in Django, use the command $ and then use the following command:Project

40. Is Django a content management system (CMS)?

No, Django is not a Content Management System (CMS). Instead, it is a Web framework and a programming tool that helps you in building elegant websites.

41. What does the Django templates contain?

A template is a simple text file. It can create any text-based format like XML, CSV, HTML, etc. A template contains variables that get replaced with values when the template is evaluated and tags (%tag%) that control the logic of the template.

42. What is the use of session framework in Django?

The session framework helps you in storing and retrieving arbitrary data on a per-site visitor basis. The data is stored on the server side and abstracts the receiving and sending of cookies. We can implement sessions through a piece of middleware.

43. How can you set up static files in Django?

Basically, we require three main things to set up static files in Django:


2) Run collect static

3) Set up a Static Files entry on the PythonAnywhere web tab

44. How to use file based sessions?

You have to set the SESSION_ENGINE settings to “django.contrib.sessions.backends.file” to use file-based session.


Theoretical Question For Interview 2

1)  A = 10, 20, 30
In the above assignment operation, what is the data type of ‘A’ that Python appreciates as?

Unlike other languages, Python appreciates ‘A’ as a tuple. When you print ‘A’, the output is (10,20,30). This type of assignment is called “Tuple Packing”.

2)  A = 1,2,3,4
      a,b,c,d = A
In the above assignment operations, what is the value assigned to the variable ‘d’?

4 is the value assigned to d.  This type of assignment is called ‘Tuple Unpacking’.

3) a = 10
     b = 20
Swap these two Variables without using the third temporary variable?

a, b = b, a  

This kind of assignment is called a parallel assignment.

4)  What is a Variable in Python?

When we say Name = ‘john’ in Python, the name is not storing the value ‘john’. But, ‘Name’ acts like a tag to refer to the object ‘john’. The object has types in Python but variables do not, all variables are just tags. All identifiers are variables in Python. Variables never store any data in Python.

5)  a = 10
     b = a
     a = 20
     print b
What is the output?
Output is 10.

6) How do you find the type and identification number of an object in Python?
type() gives the type of the object that variable is pointing to, and id() give the unique identification number of the object that variable is pointing to. Ex:

print(type(b)) #
print(id(b)) #1452987584

7)  a = 0101
    b = 2
    c = a+b

What is the Value of c?

In Python2, any number with leading 0 is interpreted as an octal number. So, variable a points to 65(Equalent in Decimal) then the variable c will be pointing to the value 67 i.e 65+2.In Python3, a=0101  (Doesn’t support syntax)

8) What are the Arithmetic Operators that Python supports?

10)  What are the basic Data Types Supported by Python?
Numeric Data types: int, long, float, NoneType
String: str
Boolean: (True, False)
NoneType: None

11) How do you check whether the two variables are pointing to the same object in Python?
In Python, we have an operation called ‘is’ operator, which returns true if the two variables are pointing to the same object.

a = "Hello world"
c = a
print(a is c) #Returns true if the two variables are pointing to the same object
print(id(a)) #64450416
print(id(c)) #64450416

12) What is for-else and while-else in Python?
Python provides an interesting way of handling loops by providing a function to write else block in case the loop is not satisfying the condition.

Example :

a = "Hello world"
c = a
print(a is c) #Returns true if the two variables are pointing to the same object
print(id(a)) #64450416
print(id(c)) #64450416

The same is true with while-else too.

13) How do you programmatically know the version of Python you are using?
The version property under sys module will give the version of Python that we are using.
import sysprint(sys.version)

14) How do you find the number of references pointing to a particular object?
The getrefcount() function in the sys module gives the number of references pointing to a particular object including its own reference. 

import sys
x = "JohnShekar"
y = xprint(sys.getrefcount(x))

Here, the object ‘JohnShekar’ is referred by x, y and getrefcount() function itself. So the output is 3. 

15) How do you dispose a variable in Python?
‘del’ is the keyword statement used in Python to delete a reference variable to an object.

import sys
x = "JohnShekar"
y = xprint(sys.getrefcount(x))
del xprint(sys.getrefcount(x)) #NameError: name 'x' is not defined

16) What is the difference between range() and xrange() functions in Python?
range() and xrange() are two functions that could be used to iterate a certain number of times in for loops in Python.
In Python 3, there is no xrange , but the range function behaves like xrange in Python 2.
If you want to write code that will run on both Python 2 and Python 3, you should use range().

# initializing a with range()
a = range(1, 10000)

# initializing a with xrange()
x = xrange(1, 10000)

print("The return type of range() is : ")

# testing the type of x
print("The return type of xrange() is : ")

17) What are the ideal naming conventions in Python?
All variables and functions follow lowercase and underscore naming convention.

Examples: is_prime(), test_var = 10 etc

Constants are all either uppercase or camel case.

Example: MAX_VAL = 50, PI = 3.14

None, True, False are predefined constants follow camel case, etc.

Class names are also treated as constants and follow camel case.

Example:    UserNames

18) What happens in the background when you run a Python file?
When we run a .py file, it undergoes two phases. In the first phase it checks the syntax and in the second phase it compiles to bytecode (.pyc file is generated) using Python virtual machine, loads the bytecode into memory and runs.

19) What is a module in Python?
A module is a .py file in Python in which variables, functions, and classes can be defined. It can also have a runnable code.

20) How do you include a module in your Python file?
The keyword “import” is used to import a module into the current file.

Example: import sys  #here sys is a predefined Python module.

21) How do you reload a Python module?
There is a function called reload() in Python, which takes module name as an argument and reloads the module.

22) What is List in Python?
The List is one of the built-in data structures in Python. Lists are used to store an ordered collection of items, which can be of different type.

Elements in a list are separated by a comma and enclosed in square brackets.

Examples of List are:

    A = [1,2,3,4]
    B = [‘a’,’b’,’c’]
    C = [1,’a’,’2’,’b’]

List in Python is sequence type as it stores ordered collection of objects/items. In Python String and tuple are also sequence types.

23)  When do you choose a list over a tuple?
When there is an immutable ordered list of elements, we choose tuple. Because we cannot add/remove an element from the tuple. On the other hand, we can add elements to a list using append () or extend() or insert(), etc., and delete elements from a list using remove() or pop().

Simple tuples are immutable, and lists are not. Based on these properties one can decide what to choose in their programming context.

24) How do you get the last value in a list or a tuple?
When we pass -1 to the index operator of the list or tuple, it returns the last value. If -2 is passed, it returns the last but one value.


a = [1,2,3,4] #List
b = (1,2,3,4) #Tuple


25) What is Index Out Of Range Error?
When the value passed to the index operator is greater than the actual size of the tuple or list, Index Out of Range error is thrown by Python.

a = [1,2,3,4] #Listprint(a[5])#IndexError: list index out of range 

26) What is slice notation in Python to access elements in an iterator?
In Python, to access more than one element from a list or a tuple we can use ‘:’ operator. Here is the syntax. Say ‘a’ is list



a = [100,200,300,400,500,600,700,800]

print(a[3:]) # Prints the values from index 3 till the end [400, 500, 600, 700, 800]
print(a[3:6])#Prints the values from index 3 to index 6. [400, 500, 600]
print(a[2::2])#Prints the values from index 2 till the end of the list with step count 2. [300, 500, 700]

The above operations are valid for a tuple too.

27) How do you convert a list of integers to a comma separated string?
List elements can be turned into a string using join function.

a = [1,2,3,4,5,6,7,8]

numbers = ','.join(str(i) for i in a)

28) What is the difference between Python append () and extend () functions?
The extend() function takes an iterable (list or tuple or set) and adds each element of the iterable to the list. Whereas append takes a value and adds to the list as a single object.


a = [1,2,3,4,5]
b = [6,7,8]
print(a)#[1, 2, 3, 4, 5, 6, 7, 8]
c = ['a','b']

print(a) #[1, 2, 3, 4, 5, 6, 7, 8, ['a', 'b']]