Day3
Day3
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
Use of static
Changes in settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS=[os.path.join(BA
SE_DIR, ‘ap2/static')]
Dumb way of
database
interaction
Problems:
Hardcoding of db connection
parameters
Boilerplate code exists
Specific to MySQL. Switching of
DBMS
Solution needs
– Use changes
Django DB Layer
everywhere.
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
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()
WAMP Server
https://sourceforge.net/projects/
wampserver/files/latest/download
https://wampserver.aviatechno.net/
Use phpmyadmin
Create database
Perform Migrations
python manage.py makemigrations
ap3
Cross Site
Request
Forgery
(CSRF)
Dept. of AIML, JNNCE
Full Stack Development with Django