Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Django Interview Questions


A list of top frequently asked Django interview questions and answers are given below.

1) What is Django?

Django is a free and open source web application framework, written in Python.

2) What does Django mean?

Django is named after Django Reinhardt, a gypsy jazz guitarist from the 1930s to early 1950s who is known as one of the best guitarists of all time.

3) Which architectural pattern does Django Follow?

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

4) Explain the architecture of Django?

Django is based on MVC architecture. It contains the following layers:
Models: It describes the Database schema and data structure.
Views: The view layer is a user interface. It controls what a user sees, the view retrieves data from appropriate models and execute any calculation made to the data and pass it to the template.
Templates: It determines how the user sees it. It describes how the data received from the views should be changed or formatted for display on the page.
Controller: Controller is the heart of the system. It handles requests and responses, setting up database connections and loading add-ons. It specifies the Django framework and URL parsing.

5) Is Django a high level web framework or low level framework?

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

6) How would you pronounce Django?

Django is pronounced JANG-oh. Here D is silent.

7) How does Django work?

Django can be broken into many components:
Models.py file: This file defines your data model by extending your single line of code into full database tables and add a pre-built administration section to manage content.
Urls.py file: It uses regular expression to capture URL patterns for processing.
Views.py file: It is the main part of Django. The actual processing happens in view.
When a visitor lands on Django page, first Django checks the URLs pattern you have created and uses information to retrieve the view. After that view processes the request, querying your database if necessary, and passes the requested information to template.
After that the template renders the data in a layout you have created and displays the page.

8) Which foundation manages Django web framework?

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

9) Is Django stable?

Yes, Django is quite stable. Many companies like Disqus, Instagram, Pinterest, and Mozilla have been using Django for many years.

10) What are 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

11) What are the advantages of using Django for web development?

  • It facilitates you to divide code modules into logical groups to make it flexible to change.
  • It provides auto-generated web admin to make website administration easy.
  • It provides pre-packaged API for common user tasks.
  • It provides template system to define HTML template for your web page to avoid code duplication.
  • It enables you to define what URL is for a given function.
  • It enables you to separate business logic from the HTML.

12) How to create a project in Django?

To start a project in Django, use the command $django-admin.py and then use the following command:
Project
_init_.py
manage.py
settings.py
urls.py

13) What are the inheritance styles in Django?

There are three possible inheritance styles in Django:
1) Abstract base classes: This style is used when you only want parent's class to hold information that you don't want to type out for each child model.
2) Multi-table Inheritance: This style is used if you are sub-classing an existing model and need each model to have its own database table.
3) Proxy models: This style is used, if you only want to modify the Python level behavior of the model, without changing the model's fields.

14) How can you set up the database in Djanago?

To set up a database in Django, you can use the command edit mysite/setting.py , it is a normal python module with module level representing Django settings.
By default, Django uses SQLite database. It is easy for Django users because it doesn't require any other type of installation. In the case of other database you have to the following keys in the DATABASE 'default' item to match your database connection settings.
Engines: you can change database by using 'django.db.backends.sqlite3' , 'django.db.backeneds.mysql', 'django.db.backends.postgresql_psycopg2', 'django.db.backends.oracle' and so on
Name: The name of your database. In the case if you are using SQLite as your database, in that case database will be a file on your computer, Name should be a full absolute path, including file name of that file.
Note: You have to add setting likes setting like Password, Host, User, etc. in your database, if you are not choosing SQLite as your database.

15) 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 controls the logic of the template.

16) Is Django a content management system (CMS)?

No, Django is not a CMS. Instead, it is a Web framework and a programming tool that makes you able to build websites.

17) What is the use of session framework in Django?

The session framework facilitates you to store and retrieve arbitrary data on a per-site visitor basis. It stores data on the server side and abstracts the receiving and sending of cookies. Session can be implemented through a piece of middleware.

18) How can you set up static files in Django?

There are three main things required to set up static files in Django:
1) Set STATIC_ROOT in settings.py
2) run manage.py collectsatic
3) set up a Static Files entry on the PythonAnywhere web tab

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

20) What is some typical usage of middlewares in Django?

Some usage of middlewares in Django is:
  • Session management,
  • Use authentication
  • Cross-site request forgery protection
  • Content Gzipping, etc.

21) What does of Django field class types do?

The Django field class types specify:
  • The database column type.
  • The default HTML widget to avail while rendering a form field.
  • The minimal validation requirements used in Django admin.
  • Automatic generated forms.

22) What is the usage of Django-admin.py and manage.py?

Django-admin.py: It is a Django's command line utility for administrative tasks.
Manage.py: It is an automatically created file in each Django project. It is a thin wrapper around the Django-admin.py. 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 setting.py file.

23) What are signals in Django?

Signals are pieces of code which contain information about what is happening. Dispatcher is used to send the signals and listen for those signals.

24) What are the two important parameters in signals?

Two important parameters in signals are:
  • Receiver: It specifies the callback function which will be connected to the signal.
  • Sender: It specifies a particular sender to receive signal from.

25) What command line is used to load data into Django?

The command line "Django-admin.py loaddata" is used to load data into Django. The command line will searches the data and loads the contents of the named fixtures into the database.


This post first appeared on GNIITSolution, please read the originial post: here

Share the post

Django Interview Questions

×

Subscribe to Gniitsolution

Get updates delivered right to your inbox!

Thank you for your subscription

×