Menu Close

django interview questions

What is Django?

  • It is a free and open-source framework that was named after Django Reinhardt who was a jazz guitarist from the 1930s.
  • Django is maintained by a non-profit organization called the Django Software Foundation.
  • The main goal of Django is to enable Web Development quickly and with ease.

How do you check for the version of Django installed on your system?

  • To check for the version of Django installed on your system, you can open the command prompt and enter the following command:
    • python -m django –version

Explain MVT?

  • Django follows the MVT or Model View Template architecture which is based on the MVC or Model View Controller architecture.
  • The main difference between these two is that Django itself takes care of the controller part.

How do you connect your Django project to the database?

  • Django comes with a default database which is SQLite.
  • To connect your project to this database, use the following commands:
  • python manage.py migrate (migrate command looks at the INSTALLED_APPS settings and creates database tables accordingly)
  • python manage.py makemigrations (tells Django you have created/ changed your models)
  • python manage.py sqlmigrate <name of the app followed by the generated id> (sqlmigrate takes the migration names and returns their SQL)

What are the various files that are created when you create a Django Project?

  • manage.py : A command-line utility that allows you to interact with your Django project
  • __init__.py : An empty file that tells Python that the current directory should be considered as a Python package
  • settings.py : Consists of the settings for the current project
  • urls.py : Contains the URL’s for the current project
  • wsgi.py : This is an entry-point for the web servers to serve the project you have created

What are ‘Models’?

  • Models are a single and definitive source for information about your data.
  • It consists of all the essential fields and behaviors of the data you have stored. Often, each model will map to a single specific database table.
  • In Django, models serve as the abstraction layer that is used for structuring and manipulating your data.
  • Django models are a subclass of the django.db.models.Model class and the attributes in the models represent database fields.

What are ‘templates’?

  • Django’s template layer renders the information to be presented to the user in a designer-friendly format.
  • Using templates, you can generate HTML dynamically.
  • The HTML consists of both static as well as dynamic parts of the content.
  • You can have any number of templates depending on the requirement of your project. It is also fine to have none of them.
  • Django has its own template system called the Django template language (DTL). Regardless of the backend, you can also load and render templates using Django’s standard admin.

What are static files?

  • Static files in Django are those files that serve the purpose of additional files such as the CSS, images or JavaScript files.
  • These files are managed by django.contrib.staticfiles.
  • These files are created within the project app directory by creating a subdirectory named as static.

What are the technical featrues of Django?

  • Admin Interface
  • Code Reusability
  • CDN Integration
  • Security Features
  • ORM
  • A huge number of third-party applications

Why is Django called loosely coupled framework?

  • Django is called a loosely coupled framework because of the MTV architecture it’s based on.
  • Django’s architecture is a variant of MVC architecture and MTV is useful because it completely separates server code from the client’s machine.

Why Django uses regular expressions to define URLs? Is it necessary to use them?

  • Django uses a very powerful format for storing URL’s that is regular expressions.
  • RegEx or regular expression is the format for sophisticated string searching algorithms.
  • It makes the searching process faster. Although it’s not necessary to use RegEx when defining URLs.

What is Django ORM?

  • Django ORM is one of the special feature-rich tools in Django. O
  • RM is an acronym for Object-Relational Mapper. This ORM enables a developer to interact with a database in a pythonic way.

List type of inheritance supported in Django?

  • Django supports 3 types of inheritance. They are
    • Abstract base classes
    • Multi-table Inheritance
    • Proxy models