Django introduction
-
Upload
valeria-leonardi -
Category
Technology
-
view
2.041 -
download
1
Transcript of Django introduction
Introduzione
Valeria Leonardi@vleonardi
Django night – 21 ottobre 2011
The (Python) Web framework for perfectionists
with deadlines
• Interpretato • Interattivo• Multiparadigma • OO, programmazione strutturata..
• Indentazione per la definizione di blocchi• Dynamic typing• Modulare
Web-Poll Application
3....2....1....
• Installare Python (2.3 <= versione <= 2.7)• Installare Django• Installare (eventuale) adattatore python per il
db
... Let’s start !• Project• django-admin.py startproject demoProject• demoProject /
__init__.py manage.py settings.py urls.py
• App• python manage.py startapp polls• polls/
__init__.py models.py tests.py views.py
MVC vs. MTVM
Model
VView
CController
MModel
TTemplate
VView
CController
DjangoFramework
Model
• Model: classe Python• Installare models nel progetto• Settings aggiungere la nostra app• Settings set engine e name
• python manage.py sql polls• python manage.py syncdb
View
• View• Return HttpResponse object OR• Raise an exception
• Esempio:• Index• Detail• Vote• Results
Template e Url
• Templates:• Index.html• Details.html• Results.html
• “Masterpage”: base.html
• URL.py: regole di routing• (regular expression, Python callback function [, optional
dictionary])
«Batteries included»• Django.contrib:• Admin-site• Authentication• Formtools• Gis• …
• Abilitare Admin-site• INSTALLED_APPS• URLS• admin.py• Python manage.py createsuperuser