DJANGO
WE MUST AND SHOULD PYTHON LEARN
JANGO IS WEBRAMEWORK
FRAMEWORK:
FRAMEworks are softwarese that is developed
and used by developers to build applications
Ex:
Bottle
Django
Giotto
Flask
Webframework:
It is a software framework that is designed to
support the development of we applications
including
Web services
Webresoureces
Web api’s
Django:
django is a free and open source web
application framework written python
#named after famous guitarist dnago Reinhardt
#created in 2003 open sourced in 2005
ADRIAN HOLOVATY AND SIMON WILLISON
DJANGO OPERATIONS:
PYTHON
HTML
CSS
BOOTSTRAP
VERSISONS:
Present version 3.0
Longtime version 2.2
Features of Django:
Stability
Execlelent documentation
Resolves security issues
Highly scalable
Utilizes seo(serch engine operation)
Huge library of packages
Django works on:
USER
VIEW
REQUEST /RESPONSE
DATABA TEMPLATES
MODEL
SE HTML/CSS/FORMS
MYSQL
SUPPORTS:
Object relational mapping
Multilongual support
Web development withlight weight web server
DATABASE CODE SQL ORM
python object\ PYTHON CODE
Top companies using Django:
1.mozilla firefox
2.instagram
3.youtube
4. dropbox
mainly using backend performance in Django
//www.djangoproject.com
MVT
M stands for MODEL
V stands for VIEW
T stands for TEMPLATE
Urls
HTTP
(urls.py)
REQUEST
FORWARD REQUEST TO
APPROPRIATE VIEW
Model
READ/ View HTTP
(model.py)
(views.py)
WRITE (HTML)
Template
(<filename>.html
MODEL:(storage)
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 representd by a
database(generally relational database such as
mysql,postgres)
File:
Model.py
View:
#view act as link between the model data and the
templates.
#it contains python logics which rquired to web
app
#this view also sends responses to the user when
the application is used, to understand briefly, we
can say that this view.py can deal with
HttpResponse
User
url
view
template
vivew
template:
a template consists of static parts of the dfesired
html output as well as some special syntax
describing how dyanamic content will be inserted
contains:
html
css
bootstrap,javascript
userdjgo use-
>urlviewsmodelviwestemplates
you
web browser
templates(html page)
urls
views
model(database)
database(orm)
model
views
templates
borwser
django setup:
How to create a Django project:
Steps:
Django-admin startproject projectname
Establish connection between views and urls
Userdjangourlviewmodeltemplate
Views.py
from django.shortcuts import render
from django.http import HttpResponse
def home(request):
return HttpResponse("this is firts project")
def demo(request):
return HttpResponse("<h1>this is demo
program<h1>")
urls.py:
from django.contrib import admin
from django.urls import path
from .views import home,demo
urlpatterns = [
path('admin/', admin.site.urls),
path("",home,name="home"),
path("demo/",demo,name="demo"),
]
C:\Users\hp\Desktop\djangoproject\firstproject1
>py manage.py runserver
http://127.0.0.1:8000/
how to create a dango app:
steps:
python manage.py starapp appname
python manage.py runserver
settings.py:
configurations
'DIRS': [os.path.join(BASE_DIR,'templates')],
Template another folder create
Static file antothr folder create
Stait5cfiles(css,javascript,html_
Media files(audio,video)
Static files:
Html pages,css,javascript,bootstrap
Django setup vscode:
Steps:
Pip install virtualenv
Virtualenv filename
Open filename open cripts
Active
Django-admin project project name
How to create a django project:
Steps:
Django-admin starproject projectnbame
Establish connection between views and urls
C:\Users\hp>cd demo
C:\Users\hp\demo>cd scripts
C:\Users\hp\demo\Scripts>activate
(demo) C:\Users\hp\demo\Scripts>
How to create a Django app:
Steps:
Python manage.py startapp appname
Python manage.py runserver
Settings.py configurations:
Static files:
Html,css,bootstrap
Model.py:
It contains the essential filds and behaviors of the
data you’re storing
generally,each model maps to a single database
table.
Create user:
Python manage.py createsuperuser