0% found this document useful (0 votes)
1 views31 pages

Day3

The document outlines a course on Full Stack Development with Django, covering topics such as dynamic URLs, Django's template system, ORM, CRUD operations, and database configuration. It emphasizes the use of Django for building database-driven websites and includes practical exercises for developing applications like student registration systems. Additionally, it highlights the benefits of the Django admin interface for managing models and performing CRUD operations efficiently.

Uploaded by

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

Day3

The document outlines a course on Full Stack Development with Django, covering topics such as dynamic URLs, Django's template system, ORM, CRUD operations, and database configuration. It emphasizes the use of Django for building database-driven websites and includes practical exercises for developing applications like student registration systems. Additionally, it highlights the benefits of the Django admin interface for managing models and performing CRUD operations efficiently.

Uploaded by

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

Full Stack Development with Django

Recap:
 Dynamic URLs
 More programs with views and
urls
 Django Template System
 Separating HTML and CSS out
 Django Template Filters
 Template Inheritance
Dept. of AIML, JNNCE
Full Stack Development with Django
Agenda:
 Using static
 Django models
 ORM and models
 CRUD operations
 MySQL
 Admin Interfaces

Dept. of AIML, JNNCE


Full Stack Development with Django

Use of static
Changes in settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS=[os.path.join(BA
SE_DIR, ‘ap2/static')]

Linking style sheets


<link rel="stylesheet" href="{%
static 's.css' %}" />

Dept. of AIML, JNNCE


Full Stack Development with Django
Develop a Django app to produce following
web page

Dept. of AIML, JNNCE


Full Stack Development with Django
Develop a Django app to produce following
web page

Dept. of AIML, JNNCE


Full Stack Development with Django

Dept. of AIML, JNNCE


Full Stack Development with Django

Dept. of AIML, JNNCE


Full Stack Development with Django

 Many complex Web sites


provide some combination of
query and actions.
 Django is well suited for making
database-driven Web sites, as it
comes with easy yet powerful
ways of performing database
queries using python.

Dept. of AIML, JNNCE


Full Stack Development with Django

Dumb way of
database
interaction

Dept. of AIML, JNNCE


Full Stack Development with Django

Problems:
 Hardcoding of db connection
parameters
 Boilerplate code exists
 Specific to MySQL. Switching of
DBMS
Solution needs
– Use changes
Django DB Layer
everywhere.

Dept. of AIML, JNNCE


Full Stack Development with Django

Configuring the database

Dept. of AIML, JNNCE


Full Stack Development with Django

Dept. of AIML, JNNCE


Full Stack Development with Django

Dept. of AIML, JNNCE


Full Stack Development with Django

An object-relational mapper (ORM) is a


code library that automates the
transfer of data stored in relational
database tables into objects that are
more commonly used in application
code. Dept. of AIML, JNNCE
Full Stack Development with Django

Django ORM vs SQL

 Python ORM is easier to express


 No need of 2 different
languages
 High-level metadata possible in
Python.
 SQL inconsistent across
database platforms.
Dept. of AIML, JNNCE
Full Stack Development with Django
Django Model Fields

Dept. of AIML, JNNCE


Full Stack Development with Django

Dept. of AIML, JNNCE


Full Stack Development with Django

Django Model Relationship Fields

Dept. of AIML, JNNCE


Full Stack Development with Django
Django Model Field options

Dept. of AIML, JNNCE


Full Stack Development with Django

Dept. of AIML, JNNCE


Full Stack Development with Django
Adding objects
modelobject.save()

Retrieving objects
modelobject.objects.all()
QuerySet with all records
modelobject.objects.filter(filter condition)
Query Set with filtered records
modelobject.objects.get(id condition)
Get specific record

Dept. of AIML, JNNCE


Full Stack Development with Django

Modifying object
First get the object with
a=modelobject.objects.get(id
condition)
Then call, a.save()
Deleting objects
First get the object with
a=modelobject.objects.get(id condition)
Then call, a.delete()

Dept. of AIML, JNNCE


Full Stack Development with Django

WAMP Server
https://sourceforge.net/projects/
wampserver/files/latest/download

https://wampserver.aviatechno.net/

Use phpmyadmin

Create database

Dept. of AIML, JNNCE


Full Stack Development with Django
nstall mysqlclient: pip install mysqlclient
Changes in settings.py
Then fill code
DATABASES = { in models.py
'default': { using ORM
'ENGINE':
'django.db.backends.mysql',
'NAME': ‘onlinemeet',
'HOST': 'localhost',
'PORT':3306,
'USER':'root',
'PASSWORD':''
}
}
Dept. of AIML, JNNCE
Full Stack Development with Django

Perform Migrations
python manage.py makemigrations
ap3

python manage.py migrate

python manage.py sqlmigrate ap3


0001
Demonstrate all CRUD operations for an
online
python meeting application
manage.py showmigrations

Dept. of AIML, JNNCE


Full Stack Development with Django

Develop a Django app that


performs student registration to a
course. It should also display list
of students registered for any
selected course. Create students
and course as models with
enrolment as ManyToMany field.

Dept. of AIML, JNNCE


Full Stack Development with Django

Cross Site
Request
Forgery
(CSRF)
Dept. of AIML, JNNCE
Full Stack Development with Django

Dept. of AIML, JNNCE


Full Stack Development with Django

Need of Django Admin Interface

 Automatically build CRUD for models


 Lot of repetitive tasks is avoided
 Can be customized
 It is an authentication based
dashboard which restricts to
privileged administrators
 Has powerful features of search and
filter Dept. of AIML, JNNCE
Full Stack Development with Django
Create superuser account to access
Admin
python manage.py createsuperuser

Register the models in admin.py


admin.site.register(modelname)

Dept. of AIML, JNNCE


Full Stack Development with Django

For student and course models


created in Lab experiment for
Module2, register admin
interfaces, perform migrations
and illustrate data entry through
admin forms.

Dept. of AIML, JNNCE

You might also like