Latest Django Interview Questions

Django interview questions

Python Django interview questions and answers

Django is a free and open-source web framework written in Python and Based on the model-view-template architectural pattern. Django web framework is a set of components that help you to develop websites earlier and easier.

While building a website, you always need a similar set of components: a way to handle user authentication (signing up, signing in, signing out), a management panel for your website.

Fortunately, other people long ago noticed that the same problem is faced by developers while making a website, so they teamed up and created frameworks that give you ready-made components to use and Django is one of them.

Top Django interview questions and answers are given below.

Download Django interview questions PDF

Django interview questions

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.

You can think Django Migrations as version control system for your database/Model. It keeps track of changes done in your application Models/Table like adding a field, deleting a model, etc. Migrations in Django are stored as an on-disk format, referred to here as “migration files”. These files are actually just normal Python files with an agreed-upon object layout, written in a declarative style. A basic migration file looks like this:



from django.db import migrations, models

class Migration(migrations.Migration):

    dependencies = [('migrations', '0001_initial')]

    operations = [
        migrations.DeleteModel('Tribble'),
        migrations.AddField('Author', 'rating', models.IntegerField(default=0)),
    ]
	

Further Reading https://docs.djangoproject.com/en/2.0/topics/migrations/

Setting Session in Django

request.session['key'] = 'value'

Unset Session in Django

del request.session['key']
Django follows MVC -MVT architecture. MVT  stand for Model View Template design Pattern which is little bit different from MVC (Model View Controller ) Pattern.

Django supports 3 types of inheritance. They are

  • Abstract base classes
  • Multi-table Inheritance
  • Proxy models
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 control the logic of the template.
Django is a high-level Python’s web framework which was designed for rapid development and clean realistic design.

The session framework helps you in storing and retrieving arbitrary data on a per-site visitor basis. The data is stored on the server side and abstracts the receiving and sending of cookies. We can implement sessions through a piece of middleware.

Django web framework is managed and maintained by an independent and non-profit organization named Django Software Foundation (DSF).
No, Django is not a Content Management System (CMS). Instead, it is a Web framework and a programming tool that helps you in building elegant websites.

By running below command on Terminal.You can check installed version of Django Framework.

py -m django --version
Following are the list of top 10 websites built on Django framework.
  1. Instagram
  2. Disqus
  3. Bitbucket
  4. Mozilla Firefox
  5. Pinterest
  6. NASA
  7. Onion
  8. The Washington Post
  9. Eventbrite
  10. Mahalo
To create a constant in Django. Open your settings.py file and add a variable like MY_CONST = “MY_VALUE”.
To use this constant in your views simply import setting like “Import settings in views.py” and use it as
settings.MY_CONST