Django Interview Questions – Set 01

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.

How would you pronounce Django?

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

What is the role of Cookie in Django?

A cookie is a small piece of information which is stored in the client browser. It is used to store user’s data in a file permanently (or for the specified time). Cookie has its expiry date and time and removes automatically when gets expire. Django provides built-in methods to set and fetch cookie.

The set_cookie() method is used to set a cookie and get() method is used to get the cookie.

The request.COOKIES[‘key’] array can also be used to get cookie values.

What is Nested Function in Swift?

A function inside a function is called a nested function.

Syntax:

func function1() {
//statements of outer function
func function2() {
//statements of inner function
}
}

What are the disadvantages of Django?

Following is the list of disadvantages of Django:

  • Django’ modules are bulky.
  • It is completely based on Django ORM.
  • Components are deployed together.
  • You must know the full system to work with it.

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

What are the signals in Django?

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

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 a 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 used the information to retrieve the view. After that view processes the request, querying your database if necessary, and passes the requested information to a template.

After that, the template renders the data in a layout you have created and displayed the page.

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 a 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 used the information to retrieve the view. After that view processes the request, querying your database if necessary, and passes the requested information to a template.

After that, the template renders the data in a layout you have created and displayed the page.

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.