Dept. of AIML, JNNCE 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 STATIC_URL = '/static/' STATICFILES_DIRS = [ os . path . join ( BASE_DIR , ‘ap2/static' )] Changes in settings.py <link rel = "stylesheet" href = "{% static 's.css' %}" /> Linking style sheets Use of static
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 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. Full Stack Development with Django
Dept. of AIML, JNNCE Dumb way of database interaction Full Stack Development with Django
Dept. of AIML, JNNCE Hardcoding of db connection parameters Boilerplate code exists Specific to MySQL. Switching of DBMS needs changes everywhere. Problems: Solution – Use Django DB Layer Full Stack Development with Django
Dept. of AIML, JNNCE Configuring the database Full Stack Development with Django
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 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. Full Stack Development with Django
Dept. of AIML, JNNCE Django Model Fields Full Stack Development with Django
Dept. of AIML, JNNCE Full Stack Development with Django
Dept. of AIML, JNNCE Django Model Relationship Fields Full Stack Development with Django
Dept. of AIML, JNNCE Django Model Field options Full Stack Development with Django
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 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 () Full Stack Development with Django
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 Install mysqlclient : pip install mysqlclient Changes in settings.py DATABASES = { 'default' : { 'ENGINE' : ' django.db.backends.mysql ' , 'NAME' : ‘ onlinemeet ' , 'HOST' : 'localhost' , 'PORT' : 3306 , ' USER' : 'root ' , 'PASSWORD' : '' } } Then fill code in models.py using ORM
Dept. of AIML, JNNCE python manage.py makemigrations ap3 python manage.py migrate python manage.py sqlmigrate ap3 0001 python manage.py showmigrations Perform Migrations Demonstrate all CRUD operations for an online meeting application Full Stack Development with Django
Dept. of AIML, JNNCE 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. Full Stack Development with Django
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 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 Full Stack Development with Django
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 For student and course models created in Lab experiment for Module2, register admin interfaces, perform migrations and illustrate data entry through admin forms. Full Stack Development with Django