It follows the Model-View-Template (MVT) architectural pattern, providing built-in features for handling common web development tasks like URL routing, database management, authentication, and templating. Django promotes code reusability, scalability, and maintainability, making it popular among developers for building complex and feature-rich web applications efficiently.
Django follows the Model-View-Template (MVT) architectural pattern.
Model: Represents the data structure of the application. It defines the database schema and interacts with the database.
View: Handles the business logic of the application. It receives requests from the client, processes them, and returns responses.
Template: Defines the presentation layer of the application. It contains HTML files with embedded template tags and filters to render dynamic content.
Don't Repeat Yourself (DRY) Principle:
Django emphasizes the DRY principle, which promotes code reusability and reduces redundancy.
It encourages developers to write modular and reusable components, such as templates, views, and models, to avoid duplicating code.
Convention over Configuration:
Django follows the convention over configuration paradigm, providing sensible defaults and conventions to minimize the need for explicit configuration.
It reduces the amount of boilerplate code by making assumptions about the project structure and naming conventions.
Object-Relational Mapping (ORM):
Django's ORM abstracts the interaction with the database, allowing developers to work with database records using Python objects.
It simplifies database operations such as querying, inserting, updating, and deleting records by providing an object-oriented interface.
Admin Interface:
Django includes a built-in admin interface that allows developers to perform CRUD (Create, Read, Update, Delete) operations on database records without writing custom views.
It automatically generates an administrative interface based on the registered models, providing a convenient way to manage application data.
Middleware:
Middleware in Django is a framework of hooks into Django's request/response processing.
It allows developers to modify incoming requests or outgoing responses globally or selectively based on certain conditions.
Middleware is commonly used for authentication, session management, and request/response logging.
11. Step-1
q Open your browser and go www.python.org
q Underneath the heading at the top that says Python Releases for Windows, click
on the link for the Latest Python 3 Release - Python 3.x.x.
q Scroll to the bottom and select either Windows x86-64 executable installer for 64-
bit or Windows x86 executable installer for 32-bit.
12. Step-2 Run the Installer
Once you have chosen and downloaded an installer, simply run it by double-clicking on
the downloaded file. A dialog should appear that looks something like this:
22. from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def hi(request):
return HttpResponse('<h1>Welcome to Django Project</h1>')
23. At first you have to be create a urls.py file in your app
from django.urls import path
from . import views #import the view
urlpatterns = [
path('', views.hi,name='Home-page'),
path(‘about', views.about,name=‘About-page'),
]
24. Add your app url in your project
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('myapp.urls'))
]
32. q Aside from the HTML generated by the server, web applications generally need to ser
ve additional files — such as images, JavaScript, or CSS — necessary to render the
complete web page. In Django, we refer to these files as “static files”.
33. First, create a directory called static in your myapp directory.
Django will look for static files there, similarly to how Django finds
templates inside myapp/templates/
34. First, create a directory called static in your myapp directory.
Django will look for static files there, similarly to how Django finds
templates inside myapp/templates/
Within the static directory you have just created, create another
directory called myapp and within that create a file called style.css.
In other words, your stylesheet should be at myapp/static/myapp/
style.css.
Because of how the AppDirectoriesFinder staticfile finder works,
you can refer to this static file in Django as myapp/style.css, similar
to how you reference the path for templates.