Instagram
youtube
Facebook
Twitter

Django Interview Questions

Que 1 - What is Django?

Ans - Django is a Python-based web framework that allows us to create and maintain quality web applications in a less complicated way. Django is easy to learn because of its built-in features like - Built-in admin panel, default databases, etc. By using Django we can create web applications in very less time.

Que 2 - What does Django mean?

Ans - Django is named after Django Reinhardt, a jazz manouche guitarist from the 1930s to early 1950s. He is considered as one of the best guitarist of all time.

Que 3 - When was Django created?

Ans - Django was created in the year 2003 when Adrian Holovaty & Simon Willison While working in the Lawrence Journal-world newspaper started creating a web application using python. Django was officially released on 21, July 2005.

Que 4 - Name some companies that use Django.

Ans - Instagram, Spotify, Youtube, Mozilla, Dropbox, Disqus, The Washington Post, Quora, Nasa Official Website, etc.

Que 5 - What are the advantages of using Django?

Ans - The main advantages of using Django  are.

  • Django works on python.

  • Django have Large Community of developers.

  • Django follows DRY and KISS principles.

  • Django REST Framework.

  • Django is very Secure.

Que 6 - What is the difference between Django project and Django App?

Ans - The main difference between the Django project and the App is Project is the collection of configuration files & apps whereas, the app is built to perform logic

Que 7 - Explain Django Architecture.

Ans - There are mainly two types of software design patterns. the first one is MVC and the second one is MVT. MVC stands for model view controller and MVT stands for the model view template. 

Whenever a user opens a website Django first searches for a URL to map. After the URL gets mapped it calls the view. Then, views interact with the models and templates. After this Django gets back to the user and renders the template.

Que 8 - What are Django Models?

Ans - The Django model is a class that is used to store essential fields and methods. Each model has its table in the database.

Que 9 - What is Django’s default database?

Ans - Django uses SQLite as its default database

Que 10 - What is the use of makemigrations command do in Django?

Ans - It is used to inform Django that we have made some changes in the database.

Que 11 - What is the difference between Django and Python?

Ans - Python is an object-oriented programming language. Django is a web framework built in Python that aims to simplify the creation of websites. By using Django we can create web applications in very less time.

Que 12 - How many databases do Django officially support? 

Ans -  There are many databases like PostgreSQL, MariaDB, MySQL, Oracle, SQLite, etc. which are officially supported by Django.

Que 13 - What is BASE_DIR in Django settings.py file?

Ans - BASE_DIR is our Django project directory. It is the same directory where our manage.py is located. All the paths we define in our project relate to BASE_DIR.

Que 14 - What is SECRET_KEY in Django settings.py file?

Ans - The Django SECRET_KEY IS used in things like session management, signing data, password hashing, etc. we have to keep this key secure from others.

Que 15 - Why DEBUG=FALSE used in production?

Ans - In production DEBUG=FALSE is used because we don’t want to show users why they are getting the error.

Que 16 - What is the difference between Django and Flask?

Ans - Django and Flask are both popular Python based web frameworks. Django is a full-stack web framework used to create large and complex web applications and Flask is a lightweight web framework used to create small web applications.

Que 17 - What are middlewares in Django?

Ans - In Django, a middleware is a regular python class these classes hold pieces of code that are processed upon every response our Django application gets.

Que 18 - What is the correct pronunciation of Django?

Ans - Django is correctly pronounced as jang-goh. Here, D is silent.

Que 19 - What are the disadvantages of using Django?

Ans - The main disadvantages of using Django are.

  • Django is not suitable for small projects.

  • Django is difficult to learn. Because you must know the full system to use it.

  • Django components are deployed together

Que 20 - What is STATIC_ROOT in Django settings.py file?

Ans - Django STATIC_ROOT defines a single folder that collects all of our static files.

Que 21 - What is STATIC_URL in Django settings.py file?

Ans - STATIC_URL is used to store the URL locations of our static files. This section tells Django where to look for static files.

Que 22 - What are Django views?

Ans - Django views is the file where the main logic of a website is present. Django views are responsible for displaying HTML content and error messages on a web page.

Que 23 - What are ALLOWED_HOSTS in Django settings.py file?

Ans - It is the list of strings representing the domain names allowed to serve our website.

Que 24 - What is a session in Django?

Ans - A session is a mechanism used by Django to track the state between our site and a particular browser. Sessions allow us to store arbitrary data of the browser.

Que 25 - What is TIME_ZONE in Django settings.py file?

Ans - In TIME_ZONE you can declare which time zone your website is using.

Que 26 - What are signals in Django?

Ans - Signals are the pieces of code used for associating events with actions. These can be implemented by developing functions that are executed when a signal calls them. A dispatcher is used to send signals.

Que 27 - What is the difference between Django project URLs and app URLs?

Ans - The URLs in the Django project urls.py folder are the "base" URLs of our site. Django first matches the request with the available paths and serves them accordingly. Django App urls.py folder contains URLs of our views.

Que 28 - What is the use of migrate command do in Django?

Ans - After we use the makemigrations command Django first prepares a migration file for us. To apply those migrations in the database we use migrate command.

Que 29 - Write code to create a Django model of contact form.

Ans

class Contact(models.Model):
              name = models.CharField(max_length=50)
              email= models.EmailField(max_length=50)
              phone = models.CharField(max_length=12)
              message= models.TextField()

Que 30 - What are templates in Django?

Ans - In Django, Templates is the file where the whole HTML content of our web application is stored. Most of the things we want to display to our users are stored in Django templates. We can have a number of templates according to our requirements.

Que 31 - What is Django admin?

Ans - Django admin is a command-line utility used to do all administrative tasks.

Que 32 - Write an expression to give an example of Django views.

Ans - we have created a view to display an HttpResponse.

from Django.shortcuts import render
from Django.shortcuts import HttpResponse

def index(request):
    return HttpResponse("An error occured")

Que 33 - What is the latest version of Django?

Ans - The latest version of Django is 4.1.3.

Que 34 - What is DTL in Django?

Ans - DTL stands for Django Template Language. we can render the dynamic information on our website using variables and tags of the Django template language.

Que 35 - Django template language is based on which template engine?

Ans - Django template language is based on the Jinja2 template engine.

Que 36 - What is WSGI Application in Django?

Ans - WSGI stands for “web server gateway interface”. It is used to forward requests from the web server to the backend of the website.

Que 37 - What are templates in Django settings.py file?

Ans - In settings.py TEMPLATES is a list of all configurations. All the settings related to the template are stored in this section.

Que 38 - What are filters in the Django template language?

Ans - Django Filters are used to modify Django variables. It is displayed by using the tag {{<variable_name>||<filter_attribute>}}. Django provides almost 60 built-in template filters.

Que 39 - Name ten filters in the Django template language.

Ans - Some filters in the Django template language are - add, addslashes, capfirst, center, default,  escape, filesizeformat, length, make_list, and random.

Que 40 - Is Django more secure than laravel?

Ans - Yes, we can say Django is more secure than laravel. But Laravel is also capable to provide security like Django but for that, an experienced and skillful developer would be must required. Using Django even a newbie can create secure web applications. 

Que 41 - What are cookies in Django?

Ans - In Django cookie is a small piece of data that is stored in the client's browser. Django has in-built methods to set and retrieve the cookie. 

Que 42 - Is Django a CMS(Content Management System)?

Ans - No, Django is not a Content Management System. It is a python based web framework to create web applications rapidly.

Que 43 - What are static files in Django?

Ans - In Django static files are the files that store and serve additional things like - CSS, Javascript, and images. Django static files are managed by “django.contrib.staticfiles”.

Que 44 - What is the difference between Django CharField and TextField?

Ans - Django CharField is used to store a small amount of text within the max length of 255 characters. And TextField is used to store a large amount of text.

Que 45 - What are forms in Django?

Ans - Django forms helps us to create HTML forms. It is similar to creating a Django model. Each field of the Django form directly maps to the HTML field.

Que 46 - Explain user authentication in Django.

Ans - Django provides its inbuilt user authentication system by using this we can manage users, groups, user permissions etc. it also facilitates us to authenticate and authorize our users.

Que 47 - What is Django ORM?

Ans - ORM stands for Object Relational Mapper. Django ORM makes a relation between the Django model and the database. Django ORM is the best tool to do database-related work. With the help of ORM, we can easily make modifications to our database using the Django terminal.

Que 48 - What is Django QuerySets?

Ans - Django has QuerySets to retrieve data from the database. A QuerySet is the list of objects of our Django model. Using QuerySet we can arrange, filter, and read data from the database.

Que 49 - What is Django Shell?

Ans - Django shell is Django’s interactive console. we can also use python commands in this shell.

Que 50 - Write an expression to display your model's objects.

Ans

Modelname.objects.all()

Que 51 - Write an expression to display all available commands in Django?

Ans - use the following command to display all available commands in Django.

django-admin help

Que 52 - What is _init_.py file in Django?

Ans - _init_.py is an empty file that instructs python to treat the directory containing the settings.py file as a python module.

Que 53 What is manage.py in Django?

Ans - manage.py is a Django command-line utility that helps us to interact with our project and to do administrative tasks.

Que 54 Write an ORM query to filter objects.

Ans - we have used ORM query to filter objects whose name starts with ‘C’.

>>> queryset = Contact.objects.filter
(name__startswith = 'C')

Que 55 What is the use of csrf_token in Django?

Ans - CSRF stands for Cross-Site Request Forgery. csrf_token is used to protect our website from malicious attacks. On every request, a unique token is generated. The incoming requests without a token are not executed.

Que 56 What are the exceptions in Django?

Ans - Django exceptions are the rare events that lead our program to failure. We can use exception classes of django.core.exceptions module to treat various exceptions.

Que 57 What are static URLs?

Ans - A static URL is a type of URL that does not change. In technical terms, we can say that these URL does not contain URL parameters. It is very difficult to maintain these types of URLs if the content of our website grows rapidly.

Que 58 What are dynamic URLs?

Ans - A Dynamic URL is a type of URL that can change. These type of URLs contains special characters like ? , = , & , + etc. the website that fetches content from a database generally uses dynamic URLs.

Que 59 Write the name of dynamic URL path converters.

Ans - The name of dynamic URL path converters in Django are int, str, slug, path, and UUID.

Que 60 Write an ORM query to delete all objects.

Ans

>>> Contact.objects.all().delete()

Que 61 How to store images in Django model?

Ans - we can store images in Django models by using ImageField.

class Image(models.Model):
    image = models.ImageField(upload_to='images')

Que 62 How to register a model in Django?

Ans - To register model in Django admin. Use the following expression in admin.py.

- my_app/admin.py

from demo.models import ModelClassName

# Register your models here.
admin.site.register(ModelClassName)

Que 63 What is Model Inheritance in Django?

Ans - Django model inheritance works similarly to the python class inheritance. There are mainly three types of model inheritances in Django.

  • Abstract Base Class Inheritance: it is used when we want our parent class to hold information so we can use it in our child classes.

  • Multi-table Model Inheritance: it is used when we are sub-classing an existing model and we want our every model to have its own table in the database.

  • Proxy Model Inheritance: it is used when we want to modify the python level behavior of the model, without changing the model’s fields.

Que 64 What is Caching in Django?

Ans - Caching is a technique to access our recent or often-used data to stored in various memory locations quickly. Django comes with a robust cashing system to store our dynamic web pages so, that we don't have to evaluate them on every request.

Que 65 What is Django REST Framework?

Ans - Django REST Framework is an open-source flexible and powerful toolkit to build RESTful APIs conveniently and rapidly. 

Que 66 What is mixin in Django?

Ans - In Django mixin is a type of multiple inheritance by which we can inherit the behavior and attribute of more than one parent class.

Que 67 Can we use multiple-column primary keys in Django?

Ans - No, we can not use multiple-columns primary keys in Django. Django only supports single-column primary keys.

Que 68 What is Ajax?

Ans - Ajax stands for Asynchronous Javascript And XML. it is a web development technique to create highly responsive and easy-to-use web applications. Using Ajax we can create better and faster web applications. it makes it possible to exchange data between the front-end and back-end or to update part of the website without reloading the whole website.

Que 69 What is jquery?

Ans - Jquery is a javascript library. It is totally dependent on javascript. Jquery allow us to do a lot of task with minimum lines of code.

Que 70 What are the advantages of using Ajax?

Ans - These are some main advantages of using ajax on the website - 

  • Ajax provides no page reload on each request.

  • Ajax makes it easy to update a specific part of the website, not the full web page.

  • Ajax makes it easy to send and receive data from the back end.

  • Ajax provides a better user experience.

  • Ajax helps to improve website speed and performance.