What is Django?
Django is a web framework in python to develop a web application in python.
Django is a free and open source web application framework, written in Python.
What are the features available in Django?
Features available in Django are
·         Admin Interface (CRUD)
·         Templating
·         Form handling
·         Internationalization
·         Session, user management, role-based permissions
·         Object-relational mapping (ORM)
·         Testing Framework
·         Fantastic Documentation
Django Interview Questions and Answers
Which architectural pattern does Django Follow?
Django follows Model-View Controller (MVC) architectural pattern.
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.
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 land 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.
Why Django should be used for web-development?
·         It allows you to divide code modules into logical groups to make it flexible to change
·         To ease the website administration, it provides auto-generated web admin
·         It provides pre-packaged API for common user tasks
·         It gives you template system to define HTML template for your web page to avoid code duplication
·         It enables you to define what URL be for a given function
·         It enables you to separate business logic from the HTML
·         Everything is in python
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.
How you can create a project in Django?
To start a project in Django, you use command $ django-admin.py and then use the command
How you can set up the Database in Django?
Ans6: You can use the command edit mysite/setting.py , it is a normal python module with module level representing Django settings.
Django uses SQLite by default; it is easy for Django users as such it won’t require any other type of installation. In the case your database choice is different that 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.
If you are not choosing SQLite as your database then setting like Password, Host, User, etc. must be added.
How you can setup static files in Django?
There are three main things required to set up static files in Django
·         Set STATIC_ROOT in settings.py
·         run manage.py collectsatic
·         set up a Static Files entry on the PythonAnywhere web tab
What does the Django templates consist of?
The 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.
Explain the use of session framework in Django?
In Django, the session framework enables 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.
How you can use file based sessions?
To use file based session you have to set the SESSION_ENGINE settings to “django.contrib.sessions.backends.file”
Explain the migration in Django and how you can do in SQL?
Migration in Django is to make changes to your models like deleting a model, adding a field, etc. into your database schema.  There are several commands you use to interact with migrations.
·         Migrate
·         Makemigrations
·         Sqlmigrate
To do the migration in SQL, you have to print the SQL statement for resetting sequences for a given app name.
django-admin.py sqlsequencreset
Use this command to generate SQL that will fix cases where a sequence is out sync with its automatically incremented field data.
What command line can be used to load data into Django?
To load data into Django you have to use the command line Django-admin.py loaddata. The command line will search the data and loads the contents of the named fixtures into the database.
What does django-admin.py makemessages command is used for?
This command line executes over the entire source tree of the current directory and abstracts all the strings marked for translation.  It makes a message file in the locale directory.
List out the inheritance styles in Django?
In Django, there is three possible inheritance styles
Abstract base classes: This style is used when you only wants parent’s class to hold information that you don’t want to type out for each child model
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
Proxy models: You can use this model, If you only want to modify the Python level behavior of the model, without changing the model’s fields
What does the Django field class types?
Field class types determines
·         The database column type
·         The default HTML widget to avail while rendering a form field
·         The minimal validation requirements used in Django admin and in automatically generated forms
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.
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.
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.
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.
Request to Download PDF

Post A Comment: