Monday, October 10, 2016

Django Interview Questions/Answers.

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

6) Is Django stable?

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

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

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

9) 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

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

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

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

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

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

15) 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

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

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

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

2 comments: