0% found this document useful (0 votes)
16 views5 pages

Django Small Tutorial

Django is a high-level web development framework for Python that facilitates the creation of complex, database-driven websites with a focus on rapid development. It follows the MVT (Model-View-Template) architecture, where Django manages the controller aspect, and offers features like an admin interface, internationalization, and security against common web attacks. Key advantages include ease of setup, support for multilingual sites, and robust form handling, making it suitable for various applications including content management systems and social networks.

Uploaded by

mukulpvt99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

Django Small Tutorial

Django is a high-level web development framework for Python that facilitates the creation of complex, database-driven websites with a focus on rapid development. It follows the MVT (Model-View-Template) architecture, where Django manages the controller aspect, and offers features like an admin interface, internationalization, and security against common web attacks. Key advantages include ease of setup, support for multilingual sites, and robust form handling, making it suitable for various applications including content management systems and social networks.

Uploaded by

mukulpvt99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

What is Django?

Django is a web development framework for Python which offers standard methods for
fast and effective website development. The primary goal of this high-level web
framework is to create complex database-driven websites. It helps you to build and
maintain quality web applications. It enables you to make the development process
smooth and time-saving for rapid development.

Why Django? Key Advantages of Django


Here are the main advantages of Django:

 Django is easy to set up and run. It offers a variety of options to get started
 It provides a ready-to-use user interface for administrative activities
 It enables multilingual websites by using its built-in internationalization system
 Helps you to meet the massive traffic demands quickly
 Django is used to build all types of content management systems, social networks as well
as scientific computing platforms.
 Django helps you to provide end-to-end application testing
 Helps you to document your API with an HTML output

Features of Django

r the URLs in your application

-in authentication system


-oriented programming language database which offers best in class data
storage and retrieval
admin interface feature allows the functionality of adding, editing and
deleting items. You can customize the admin panel as per your need.

Django Architecture: MVC and MVT


Below is a detailed architecture of Django:
MVC Pattern:

When talking about applications which provide UI (web or desktop), we usually talk about
MVC architecture. MVC pattern is based on Model, View, and Controller.

The Model defines the data structure and takes to care for querying the database.

The View defines what data should be presented and returns an HTTP response.

The Controller is that part of the application that handles the user interaction.

Django MVC-MVT pattern

The Model-View-Template (MVT) is a different concept compared to MVC. The main


difference between these two architectural patterns is that Django itself manages the
Controller part (software code that controls the interactions between the Model and View).
The template is an HTML file which mixed with Django Template Language file which
also called DTL.

The below-given diagram shows how all the components of the MVT pattern interact with
each other to serve specific to a user request.

As seen in above diagram, a user requests for a resource to Django. Django acts as a
controller and checks to the available resource in URL.

If URL maps, a view is called which interacts with model and template. Django then
responds to the user and sends a template as a response.

Components of Django
Form:

Django has a powerful form library which handles rendering forms as HTML. The library
helps in validating submitted data and converting it to Python types.

Authentication:

It handles user accounts, groups, cookie-based user sessions, etc.

Admin:

It reads metadata in your models to provide a robust interface which can be used to
manage content on your site.

Internationalization:

Django provides support for translating text into various languages, locale-specific
formatting of dates, times, numbers, and timezones.

Security:

Django provides safeguard against the following attacks:

 Cross-Site Request Forgery (CSRF)


 Cross-site scripting
 SQL injection

Django Views

In the model view controller (MVC) architecture, the view component deals with how data is
presented to users for consumption and viewing. In the Django framework, views are Python
functions or classes that receive a web request and return a web response. The response can be
a simple HTTP response, an HTML template response, or an HTTP redirect response that
redirects a user to another page. Views hold the logic that is required to return information as a
response in whatever form to the user. As a matter of best practice, the logic that deals with views
is held in the views.py file in a Django app.
FAQs

Explain Django Architecture?

Django follows the MVT (Model View Template) pattern which is based on the Model View
Controller architecture. It’s slightly different from the MVC pattern as it maintains its own
conventions, so, the controller is handled by the framework itself. The template is a presentation
layer. It is an HTML file mixed with Django Template Language (DTL). The developer provides
the model, the view, and the template then maps it to a URL, and finally, Django serves it to the
user.

2. Explain the django project directory structure?

 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 - Comprises the configurations of the current project like DB connections.
 urls.py - All the URLs of the project are present here
 wsgi.py - This is an entry point for your application which is used by the web servers to serve
the project you have created

What are models in Django?

A model in Django refers to a class that maps to a database table or database collection. Each
attribute of the Django model class represents a database field. They are defined in
app/models.py

What are templates in Django or Django template language?

Templates are an integral part of the Django MVT architecture. They generally comprise HTML,
CSS, and js in which dynamic variables and information are embedded with the help of views.
Some constructs are recognized and interpreted by the template engine. The main ones are
variables and tags.

A template is rendered with a context. Rendering just replaces variables with their values,
present in the context, and processes tags. Everything else remains as it is.

What are views in Django?


A view function, or “view” for short, is simply a Python function that takes a web request and
returns a web response. This response can be HTML contents of a web page, or a redirect, or a
404 error, or an XML document, or an image, etc.

Example:-
from django.http import HttpResponse
def sample_function(request):
return HttpResponse(“Welcome to Django”)

There are two types of views:

 Function-Based Views: In this, we import our view as a function.


 Class-based Views: It’s an object-oriented approach

What is Django ORM?

This ORM (an acronym for Object Relational Mapper) enables us to interact with databases in a
more pythonic way like we can avoid writing raw queries, it is possible to retrieve, save, delete
and perform other operations over the database without ever writing any SQL query. It works as
an abstraction layer between the models and the database

You might also like