😀 There are "45" Excellent Django interview Questions to help you make the new concepts, you are learning as an interview Purpose. It's really very most important:
1.What is Django?
Ans: Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design. Built by experienced developers, it takes care of much of the hassle of Web development, so you can focus on writing your app without needing to reinvent the wheel. It’s free and open source.
2.Which architectural pattern does Django Follow?
Ans: Django follows the Model-View Template (MVT) architectural pattern.
3.Which foundation manages the Django web framework?
Ans: Django web framework is managed and maintained by
an independent and non-profit organization named
Django Software Foundation (DSF).
4.What are the features available in the Django web framework?
Ans: Features available in the Django web framework are:
1.Admin Interface (CRUD)
2.Templating
3.Form handling
4. Internationalization
5. Session, user management, role-based permissions
6. Object-relational mapping (ORM)
7.Testing Framework
8.Fantastic Documentation
5.What are the advantages of using Django for web development?
Ans: It facilitates you to divide code modules into logical groups to make it flexible to change.
1.It provides auto-generated web admin to make website administration easy.
2.It provides pre-packaged API for common user tasks.
3. It provides a template system to define the HTML template for your web page to avoid code duplication.
4. It enables you to define what URL is for a given function.
5. It enables you to separate business logic from the HTML.
6.What is the difference between a project and an app in Django?
Ans: In Django, a project is an entire application and an app is a
module inside the project that deals with one specific requirement.
E.g., if the entire project is an e-commerce site, then inside the project
we will have several apps, such as the retail site app, the buyer
site app, the shipment site app, etc.
7.How to create a project in Django?
Ans: To start a project in Django, use the command $django-admin.py and then use the following command:
Project:
1._init_.py
2.manage.py
3.settings.py
4.urls.py
8.How can you set up static files in Django?
Ans: There are three main things required to set up static files in Django:
1. Set STATIC_ROOT in settings.py
2. run manage.py collect static
3. set up a Static Files entry on the PythonAnywhere web tab
9.What is the command to start Django’s built-in development server?
Ans-manage.py run server
10.What does a urls.py file do in Django?
Ans-It contains URL matching patterns and their corresponding view methods.
11.What is the purpose of settings.py?
Ans-To configures settings for the Django project.
12.What is the definition of a good Django app?
Ans-A good Django app provides a small, specific piece of functionality that can be used in any number of Django projects.
13.What is Model Form used for.
Ans-To define a form based on an existing model
14.What is the command to start a new Django project called ‘my project’?
Ans-Django-admin.py start project my project.
15.What does the Django command `manage.py validate` do?
Ans-Checks for errors in your models.
16.What is Django Admin Interface?
Ans: Django comes with a fully customizable in-built admin interface, which lets us see and make changes to all the data in the database of registered apps and models. To use a database table with the admin interface. we need to register the model in the admin.py file.
17.What is a model in Django?
Ans: A model is a Python class in Django that is derived from the django.db.models.Model class. A model is used in Django to represent a table in a database. It is used to interact with and get results from the database tables of our application.
18.What are migrations in Django?
Ans: A migration in Django is a Python file that contains changes we make to our models so that they can be converted into a
database schema in our DBMS. So, instead of manually making changes to our database schema by writing queries in our DBMS
shell, we can just make changes to our models. Then, we can use
Django to generate migrations from those model changes and run those migrations to make changes to our database schema.
19.What are views in Django?
Ans: A view in Django is a class and/or a function that receives a v
request and returns a response. A view is usually associated with URL patterns, and the logic encapsulated in a view is run when a request to the URL associated with it is run. A view, among other things, gets data from the database using models, passes that data to the templates and sends back the rendered template to the user as an HttpResponse.
20.Mention the architecture of Django architecture?
Ans: Django architecture consists of
1.Models: It describes your database schema and your data structure
2.Views: 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
3.Templates: It determines how the user sees it. It describes how
the data received from the views should be changed or
4.formatted for display on the page
5.Controller: The Django framework and URL parsing
21.Give an example of how you can write a VIEW in Django?
Ans: Views are Django functions that take a request and return a response.
To write a view in Django we take a simple example of “Guru99_home” which uses the template Guru99_home.html and uses the date-time module to tell us what the time is whenever the page is refreshed. The file we required to the edit is called view.py, and it will be inside my site/my app/Copy the below code into it and save the file from DateTime import DateTime from Django. shortcuts import render def home (request); return render(request, ‘Guru99_home.html’, {‘right_now’: DateTime.utcnow()}) Once you have determined the VIEW, you can uncomment this line in urls.py
# URL ( r ‘^$’, ‘my site.myapp.views.home’, the name ‘Shahjahan73’),
The last step will reload your web app so that the changes are noticed by the webserver.
22.Explain how you can set up static files in Django?
Ans: There are three main things required to set up static files in Django
Set STATIC_ROOT in settings.py run manage.py collect state set up a Static Files entry on the PythonAnywhere web tab
23.Mention what do the Django templates consists of?
Ans: The 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.
24.Explain the migration in Django and how you can do it in SQL?
Ans: Migration in Django is to make changes to your models like deleting a model, adding a field, etc. into your database schema. There are several commands you use to interact with migrations.
Migrate
mak emigrations
Sqlmigrate
To do the migration in SQL, you have to print the SQL statement
for resetting sequences for a given app name.
Django-admin.py SQL sequences
Use this command to generate SQL that will fix cases where a
the sequence is out of sync with its automatically incremented field data.
25.List out the inheritance styles in Django?
Ans: In Django, there are three possible inheritance styles
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: You can use this model If you only want to modify the Python level behavior of the model, without changing the model’s fields
26.What makes up Django architecture?
Ans: Django runs on MVC architecture. Following
are the components that make up Django architecture:
1.Models: Models elaborate back-end stuffs like database schema.(relationships)
2.Views: Views control what is to be shown to the end-user.
3.Templates: Templates deal with the formatting of view.
4.Controller: Takes entire control of Models. An MVC framework can be compared to a Cable TV with a remote. A Television set is a View(that) interacts with the end-user), cable the provider is model(that works in back-end) and Controller is a remote that controls which channel to select and display it through the view.
27.What are inheritance types in Django?
Ans: There are 3 inheritance types in Django
1.Abstract base classes
2.Multi-table Inheritance
3.Proxy models
28.What do you think are the limitations of Django Object relation mapping(ORM)?
Ans: If the data is complex and consists of multiple joins using the SQL will be clearer If Performance is a concern for you, ORM isn’t your choice. Generally. Object-relation-mapping is considered a good option to construct an optimized query, SQL has an upper hand when compared to ORM.
29.What are the features available in the Django web framework?
Ans: Features available in the Django web framework are:
1.Admin Interface (CRUD)
2.Templating
3.Form handling
4.Internationalization
The session, user management, role-based permissions
5.Object-relational mapping (ORM)
6.Testing Framework
7.Fantastic Documentation
30.What are the advantages of using Django for web development?
Ans:
1.It facilitates you to divide code modules into logical groups to make it flexible to change.
2..It provides auto-generated web admin to make website administration easy.
3.It provides pre-packaged API for common user tasks.
4.It provides a template system to define the HTML template for your web page to avoid code duplication.
5.It enables you to define what URL is for a given function.
6.It enables you to separate business logic from the HTML.
31.What are the inheritance styles in Django?
Ans: There are three possible inheritance styles in Django:
(1) Abstract base classes: This style is used when you only want the 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.
32.Explain the working of Django?
Ans. Django can be broken into the following components:
1.Models.py: Models.py file will define your data model by extending
your single line of code into full database tables and add a pre-built
administration section to manage content.
2.Urls.py: Uses a regular expression to capture URL patterns for processing.
3.Views.py: This is the main part of Django. The presentation logic is defined in this.
When a visitor visits the Django page, first Django checks the URLs pattern you have created and uses this information to retrieve the view. Then it is the responsibility of view to processes the request, querying your database
if necessary, and passes the requested information to a template.
Then template renders the data in a layout you have created and displayed the page.
33.Explain the advantages of Django?
Ans.Advantages of Django Web development framework Django is a Python’s
the framework is easy to learn.
1.It is clear and readable.
2.It is versatile.
3.It is fast to write.
No loopholes in design.
4.It is secure.
5.It is scalable.
6.It is versatile.
34.What are the disadvantages of Django?
Ans. Following is the list of disadvantages of Django:
1.Django’s modules are bulky.
2.It is completely based on Django ORM.
3.Components are deployed together.
4.You must know the full system to work with it.
35.Can you set up static files in Django? How?
Ans. Yes, we can. We need to set three main things to set up static files in Django:
1.Set STATIC_ROOT in settings.py
2.run manage.py collect static
3.Static Files entry on the PythonAnywhere web tab
36.What is the difference between Flask and Django?
Ans-
Comparison Factor Django Flask
Project Type Supports large projects Built for smaller projects
Templates, Admin and ORM Built-in Requires installation
Ease of Learning Requires more learning and practice Easy to learn
Flexibility Allows complete web development without the need for third-party tools
More flexible as the user can select any third-party
tools according to their choice and requirements
Visual Debugging Does not support Visual Debug Supports Visual Debug
Type of framework Batteries included Simple lightweight
Bootstrapping- tool Built-it Not available
37.How to Create APIs in Django?
Ans-Create a project directory, create a python virtual environment and activate it, install Django, and Django rest framework using the pip install command. In the same project directory, create a project using the command Django-admin.py
start project API. Start the app. Add the rest_framework and the Django app to INSTALLED_APPS to settings. Open the api/urls.py and add URLs for the Django app. We can then create models and make migrations, create serializers, and finally wiring up the views.
38.What is DRF of the Django Rest Framework?
Ans-Django Rest Framework (DRF) is a powerful module for building web APIs. It’s very easy to build model-backed APIs that have
authentication policies and are browsable.
39.How a request is processed in Django?
Ans-When the user makes a request of your application, a
WSGI handler is instantiated, which:
imports your settings.py file and Django’s exception classes.
loads all the middleware classes it finds in the MIDDLEWARE_CLASSES or
MIDDLEWARES(depending on Django version) tuple located in settings.py
builds four lists of methods that handle the processing of the request, view, response, and exception.
loops through the request methods, running them in order
resolves the requested URL
loops through each of the view processing methods
calls the view function (usually rendering a template)
processes any exception methods
loops through each of the response methods, (from the inside out, reverse
order from request middlewares)
finally builds a return value and calls the callback function to the webserver
40.What is some typical usage of middlewares in Django?
Ans-Some usage of middlewares in Django is:
1.Session management,
Use authentication
2.Cross-site request forgery protection
3.Content Gzipping
41.What is the usage of Django-admin.py and manage.py?
Ans-
1.Django-admin.py: It is a Django's command-line utility for administrative tasks.
2.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:
3.It puts your project's package on sys.path.
4.It sets the DJANGO_SETTING_MODULE environment variable to points to your project's setting.py file.
42.How to handle URLs in Django?
Ans-To handles URL, the Django.urls module is used by the Django framework.
Let's open the file urls.py of the project and see the what it looks like:
// urls.py
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
See, Django already has mentioned a URL here for the admin.
The path function takes the first argument as a route of string or regex type.
The view argument is a view function which is used to return a response (template) to the user.
The Django.urls module contains various functions, path(route, view, kwargs, name)
is one of those which is used to map the URL and call the specified view.
43.What are the different types of Django Exception Classes?
Ans-The django.core.exceptions module contains the following classes
Exception Description:
1.AppRegistryNotReady It is raised when attempting to use models before the app loading process.
2.ObjectDoesNotExist The base class for DoesNotExist exceptions.
3.EmptyResultSet If a query does not return any result, this exception is raised.
4.FieldDoesNotExist It raises when the requested field does not exist.
5.MultipleObjectsReturned This exception is raised by a query if only one object is expected, but multiple objects are returned.
6.SuspiciousOperation This exception is raised when a user has performed an operation that should be considered suspicious from a security perspective.
7.PermissionDenied It is raised when a user does not have permission to perform the action requested.
8.ViewDoesNotExist It is raised by Django.urls when a requested view does not exist.
9.MiddlewareNotUsed It is raised when a middleware is not used in the server configuration.
10.ImproperlyConfigured The ImproperlyConfigured exception is raised when Django is somehow improperly configured.
11.FieldError It is raised when there is a problem with a model field.
12.ValidationError It is raised when data validation fails to form or model field validation.
44.Django Project MVT Structure
Ans-Django is based on MVT (Model-View-Template) architecture. MVT is a software design pattern for developing a web application. MVT Structure has the following three parts:
1.Model: Model is going to act as the interface of your data. It is responsible for maintaining data. It is the logical data structure behind the entire application and is represented by a database (generally relational databases such as MySql, Postgres). To check more, visit – Django Models
2.View: The View is the user interface — what you see in your browser when you render a website. It is represented by HTML/CSS/Javascript and Jinja files. To check more, visit – Django Views.
3.Template: A template consists of static parts of the desired HTML output as well as some special syntax describing how dynamic content will be inserted. To check more.
45.What is the Relation Django and SQLite(Database Connectivity)?
Ans-Django in its 'out-of-the-box' state is set up to communicate with SQLite a lightweight relational database included with the Python distribution. So by default, Django automatically creates an SQLite database for your project. In addition to SQLite, Django officially supports (i.e. included in Django itself) three other popular relational databases that include: PostgreSQL, MySQL, and Oracle.
And unofficially (i.e. with third party packages) Django supports connectivity to other relational
databases that include: SAP (Sybase) SQL Anywhere, IBM DB2, and Firebird, as well
as the ADO (ActiveX Data Objects) and ODBC (Open Database Connectivity) interfaces, the
last two of which are standard for connecting to Microsoft SQL Server and
the latter is supported by most relational database brands.
The Django configuration to connect to a database is done inside the settting.py file of a Django project in the DATABASES variable.
Conclusion-In this tutorial you will have to learn Django(Python framework) Excellent
top "45" famous Interview question and Answer
So I hope you liked these tutorials. If you have any questions or suggestions related to the Django interview purpose please comment below and let us know.
Finally, if you find this post informative, then share it with your friends on Facebook, Twitter, Instagram.
Thank you...
good for python developer
ReplyDelete