Web Application Development Django Framework Fabrizio Lapiello IT Eng. Student http://flapiello.com
Table of contents “Step by Step” 2
Table of contents “Step by Step” Step 0: Django Introduction Step 1: Admin Panel Step 2: URL Step 3: Creating an application 2
Step 0 Introduction: Django Framework 3
Step 0 Introduction: Django Framework 0) The Framework 1) MTV Pattern 2) DBMS 3) Setup 4) “Hello World” 4.1) Creating and compiling 4.2) Creating a View 3
The Framework: What is Django? 4
The Framework: What is Django? Django is a great framework for building Web 2.0 applications! It 'was designed to improve development time and quality. http://www.djangoproject.org 4
MTV Pattern “Model-Template-View” 5
MTV Pattern “Model-Template-View” A pattern that helps to separate the user interface level from the other parts of the system. Model - contains classes whose instances represent the data to display and manipulate. Template - contains objects that control and manage user interaction with the model and view layers. View - contains the objects used in the UI to display the data in the model. 5
DBMS “Database management system” Some of the most well-known DBMS used in Django: 6
DBMS “Database management system” Some of the most well-known DBMS used in Django: 6
Prior Knowledge 7
Prior Knowledge ...that’s all! 7
Good reasons to learn Python Well-known companies have adopted it for their business: 8
Good reasons to learn Python Well-known companies have adopted it for their business: 8
Setup 9
Setup Download: http://www.djangoproject.com/download/ Setup Guide: http://docs.djangoproject.com/en/dev/intro/install/ Official Documentation: http://docs.djangoproject.com/ 9
Creating and compiling project 10
Creating and compiling project $ django-admin.py startproject hello -> __Init__.py manage.py settings.py urls.py $ python manage.py runserver -> 0 Error Found http://127.0.0.1:8000 -> Worked!! 10
Creating a view First Step 11
Creating a view First Step First of all combining a URL to a view -> http://127.0.0.1:8000/hello Open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) 11
Creating a view First Step First of all combining a URL to a view -> http://127.0.0.1:8000/hello Open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) 11
Creating a view First Step First of all combining a URL to a view -> http://127.0.0.1:8000/hello Open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) Regular expression that indicates the beginning and the end of the URL. 11
Creating a view First Step First of all combining a URL to a view -> http://127.0.0.1:8000/hello Open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) Regular expression that indicates the beginning and the end of the URL. 11
Creating a view First Step First of all combining a URL to a view -> http://127.0.0.1:8000/hello Open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) Regular expression that indicates the beginning Combining Url/Vista and the end of the URL. 11
Creating a view Second Step The view is simply a Python method that returns the data. In the root of the project we create the views.py file and insert the following method: from django.http import HttpResponse def hello(request): return HttpResponse(“Hello World”) Now type in a terminal: $ python manage.py runserver 12
Step 1 Admin Panel 13
Step 1 Admin Panel 0) Creating applications 1) Creating models 2) Add a Database 3) ORM 4) Creating Admin Panel 13
Creating Applications Is good practice to structure the project into sub-applications in order to have greater control over the entire system to be developed! $ python manage.py startapp test If there aren't errors in the root of the project should have a folder named "test" with the following files inside __init__.py models.py views.py Inatalled_Apps indicate the presence in the settings.py file, application "test" by simply inserting his name in quotes at the bottom of the list. 14
Creating models Change the models.py file in the folder "test "... from django.db import models class Persona (models.Model): nome = models.CharField(max_length=50) cognome = models.CharField(max_length=50) def __unicode__(self): return u"%s %s" % (self.nome, self.cognome) class Meta: verbose_name_plural ="Persone" 15
Add a Database Edit the settings.py file in the following way: DATABASES = { 'default': { 'ENGINE': 'sqlite3', #NAME del dbms es (oracle, mysql etc..) 'NAME': 'test.db', #DB NAME 'USER': '', #USERNAME 'PASSWORD': '', #Password 'HOST': '', #DMBS ADDRESS 'PORT': '', #PORT } } 16
ORM “Object-Relational Mapping” 17
ORM “Object-Relational Mapping” An ORM is a kind of linker between objects and relational databases. 17
ORM “Object-Relational Mapping” An ORM is a kind of linker between objects and relational databases. Through this linker the created objects with a high-level language are included in the relational database. 17
ORM “Object-Relational Mapping” An ORM is a kind of linker between objects and relational databases. Through this linker the created objects with a high-level language are included in the relational database. 17
ORM “Object-Relational Mapping” An ORM is a kind of linker between objects and relational databases. Through this linker the created objects with a high-level language are included in the relational database. 17
ORM “Object-Relational Mapping” An ORM is a kind of linker between objects and relational databases. Through this linker the created objects with a high-level language are included in the relational database. $ python manage.py syncdb 17
Creating Admin Panel First Step Open the file settings.py INSTALLED_APPS and insert in the application for the board of directors as follows: INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.admin', ) 18
Creating Admin Panel Second Step Associate a URL to the application, then edit the urls.py file as follows: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)), (r'^hello/$', "views.hello"), ) 19
Creating Admin Panel Second Step Associate a URL to the application, then edit the urls.py file as follows: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', ! (r'^admin/', include(admin.site.urls)), là (r'^hello/$', "views.hello"), oi ) E t V 19
Step 2 URL 20
Step 2 URL 0) URL 1) Creating an URL 20
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog 21
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog 21
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog 21
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog 21
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog 21
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
Creating URL To create a URL like the following -> http://127.0.0.1:8000/hello you have to combine the view of the URL, so, you have to open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) 22
Creating URL To create a URL like the following -> http://127.0.0.1:8000/hello you have to combine the view of the URL, so, you have to open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) 22
Creating URL To create a URL like the following -> http://127.0.0.1:8000/hello you have to combine the view of the URL, so, you have to open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) 22
Creating URL To create a URL like the following -> http://127.0.0.1:8000/hello you have to combine the view of the URL, so, you have to open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) Regular expression that indicates the beginning and the end of the URL. 22
Creating URL To create a URL like the following -> http://127.0.0.1:8000/hello you have to combine the view of the URL, so, you have to open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) Regular expression that indicates the beginning Combining Url/Vista and the end of the URL. 22
Step 3 Creating an application 23
Step 3 Creating an application DEMO 23
Contacts A Q F Fabrizio Lapiello IT Eng. Student Email: flapiello@aol.com Web: http://lfapiello.com

Web application development with Django framework

  • 1.
    Web Application Development Django Framework Fabrizio Lapiello IT Eng. Student http://flapiello.com
  • 2.
    Table of contents “Step by Step” 2
  • 3.
    Table of contents “Step by Step” Step 0: Django Introduction Step 1: Admin Panel Step 2: URL Step 3: Creating an application 2
  • 4.
  • 5.
    Step 0 Introduction: Django Framework 0) The Framework 1) MTV Pattern 2) DBMS 3) Setup 4) “Hello World” 4.1) Creating and compiling 4.2) Creating a View 3
  • 6.
  • 7.
    The Framework: What is Django? Django is a great framework for building Web 2.0 applications! It 'was designed to improve development time and quality. http://www.djangoproject.org 4
  • 8.
  • 9.
    MTV Pattern “Model-Template-View” A pattern that helps to separate the user interface level from the other parts of the system. Model - contains classes whose instances represent the data to display and manipulate. Template - contains objects that control and manage user interaction with the model and view layers. View - contains the objects used in the UI to display the data in the model. 5
  • 10.
    DBMS “Database management system” Some of the most well-known DBMS used in Django: 6
  • 11.
    DBMS “Database management system” Some of the most well-known DBMS used in Django: 6
  • 12.
  • 13.
    Prior Knowledge ...that’s all! 7
  • 14.
    Good reasons tolearn Python Well-known companies have adopted it for their business: 8
  • 15.
    Good reasons tolearn Python Well-known companies have adopted it for their business: 8
  • 16.
  • 17.
    Setup Download: http://www.djangoproject.com/download/ Setup Guide: http://docs.djangoproject.com/en/dev/intro/install/ Official Documentation: http://docs.djangoproject.com/ 9
  • 18.
  • 19.
    Creating and compilingproject $ django-admin.py startproject hello -> __Init__.py manage.py settings.py urls.py $ python manage.py runserver -> 0 Error Found http://127.0.0.1:8000 -> Worked!! 10
  • 20.
    Creating a view First Step 11
  • 21.
    Creating a view First Step First of all combining a URL to a view -> http://127.0.0.1:8000/hello Open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) 11
  • 22.
    Creating a view First Step First of all combining a URL to a view -> http://127.0.0.1:8000/hello Open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) 11
  • 23.
    Creating a view First Step First of all combining a URL to a view -> http://127.0.0.1:8000/hello Open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) Regular expression that indicates the beginning and the end of the URL. 11
  • 24.
    Creating a view First Step First of all combining a URL to a view -> http://127.0.0.1:8000/hello Open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) Regular expression that indicates the beginning and the end of the URL. 11
  • 25.
    Creating a view First Step First of all combining a URL to a view -> http://127.0.0.1:8000/hello Open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) Regular expression that indicates the beginning Combining Url/Vista and the end of the URL. 11
  • 26.
    Creating a view Second Step The view is simply a Python method that returns the data. In the root of the project we create the views.py file and insert the following method: from django.http import HttpResponse def hello(request): return HttpResponse(“Hello World”) Now type in a terminal: $ python manage.py runserver 12
  • 27.
  • 28.
    Step 1 Admin Panel 0) Creating applications 1) Creating models 2) Add a Database 3) ORM 4) Creating Admin Panel 13
  • 29.
    Creating Applications Is goodpractice to structure the project into sub-applications in order to have greater control over the entire system to be developed! $ python manage.py startapp test If there aren't errors in the root of the project should have a folder named "test" with the following files inside __init__.py models.py views.py Inatalled_Apps indicate the presence in the settings.py file, application "test" by simply inserting his name in quotes at the bottom of the list. 14
  • 30.
    Creating models Change themodels.py file in the folder "test "... from django.db import models class Persona (models.Model): nome = models.CharField(max_length=50) cognome = models.CharField(max_length=50) def __unicode__(self): return u"%s %s" % (self.nome, self.cognome) class Meta: verbose_name_plural ="Persone" 15
  • 31.
    Add a Database Editthe settings.py file in the following way: DATABASES = { 'default': { 'ENGINE': 'sqlite3', #NAME del dbms es (oracle, mysql etc..) 'NAME': 'test.db', #DB NAME 'USER': '', #USERNAME 'PASSWORD': '', #Password 'HOST': '', #DMBS ADDRESS 'PORT': '', #PORT } } 16
  • 32.
  • 33.
    ORM “Object-Relational Mapping” An ORM is a kind of linker between objects and relational databases. 17
  • 34.
    ORM “Object-Relational Mapping” An ORM is a kind of linker between objects and relational databases. Through this linker the created objects with a high-level language are included in the relational database. 17
  • 35.
    ORM “Object-Relational Mapping” An ORM is a kind of linker between objects and relational databases. Through this linker the created objects with a high-level language are included in the relational database. 17
  • 36.
    ORM “Object-Relational Mapping” An ORM is a kind of linker between objects and relational databases. Through this linker the created objects with a high-level language are included in the relational database. 17
  • 37.
    ORM “Object-Relational Mapping” An ORM is a kind of linker between objects and relational databases. Through this linker the created objects with a high-level language are included in the relational database. $ python manage.py syncdb 17
  • 38.
    Creating Admin Panel First Step Open the file settings.py INSTALLED_APPS and insert in the application for the board of directors as follows: INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.admin', ) 18
  • 39.
    Creating Admin Panel Second Step Associate a URL to the application, then edit the urls.py file as follows: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', (r'^admin/', include(admin.site.urls)), (r'^hello/$', "views.hello"), ) 19
  • 40.
    Creating Admin Panel Second Step Associate a URL to the application, then edit the urls.py file as follows: from django.contrib import admin admin.autodiscover() urlpatterns = patterns('', ! (r'^admin/', include(admin.site.urls)), là (r'^hello/$', "views.hello"), oi ) E t V 19
  • 41.
  • 42.
    Step 2 URL 0) URL 1) Creating an URL 20
  • 43.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog 21
  • 44.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog 21
  • 45.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog 21
  • 46.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog 21
  • 47.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog 21
  • 48.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
  • 49.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
  • 50.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
  • 51.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
  • 52.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
  • 53.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
  • 54.
    URL Uniform Resource Locator Benefit of having "ordered" URL - Easy to remember - Palatability by search engines - Durable n g! yi r rif Ho Example: 1) http://nomedominio.com/index.php?option=com_content&view=category&layout=blog&id=3&Itemid=17 2) http://nomedominio.com/blog to be rep lac ed 21
  • 55.
    Creating URL To createa URL like the following -> http://127.0.0.1:8000/hello you have to combine the view of the URL, so, you have to open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) 22
  • 56.
    Creating URL To createa URL like the following -> http://127.0.0.1:8000/hello you have to combine the view of the URL, so, you have to open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) 22
  • 57.
    Creating URL To createa URL like the following -> http://127.0.0.1:8000/hello you have to combine the view of the URL, so, you have to open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) 22
  • 58.
    Creating URL To createa URL like the following -> http://127.0.0.1:8000/hello you have to combine the view of the URL, so, you have to open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) Regular expression that indicates the beginning and the end of the URL. 22
  • 59.
    Creating URL To createa URL like the following -> http://127.0.0.1:8000/hello you have to combine the view of the URL, so, you have to open the file urls.py and insert the following string as the last parameter: -> (r’^hello/$’, “views.hello”) Regular expression that indicates the beginning Combining Url/Vista and the end of the URL. 22
  • 60.
    Step 3 Creating anapplication 23
  • 61.
    Step 3 Creating anapplication DEMO 23
  • 63.
    Contacts A Q F Fabrizio Lapiello IT Eng. Student Email: flapiello@aol.com Web: http://lfapiello.com