django introduction

12
Introduzione Valeria Leonardi @vleonardi Django night – 21 ottobre 2011

Upload: valeria-leonardi

Post on 14-May-2015

447 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Django introduction

Introduzione

Valeria Leonardi@vleonardi

Django night – 21 ottobre 2011

Page 2: Django introduction

The (Python) Web framework for perfectionists

with deadlines

Page 3: Django introduction

• Interpretato • Interattivo• Multiparadigma • OO, programmazione strutturata..

• Indentazione per la definizione di blocchi• Dynamic typing• Modulare

Page 4: Django introduction

Web-Poll Application

Page 5: Django introduction

3....2....1....

• Installare Python (2.3 <= versione <= 2.7)• Installare Django• Installare (eventuale) adattatore python per il

db

Page 6: Django introduction

... 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

Page 7: Django introduction

MVC vs. MTVM

Model

VView

CController

MModel

TTemplate

VView

CController

DjangoFramework

Page 8: Django introduction

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

Page 9: Django introduction

View

• View• Return HttpResponse object OR• Raise an exception

• Esempio:• Index• Detail• Vote• Results

Page 10: Django introduction

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])

Page 11: Django introduction

«Batteries included»• Django.contrib:• Admin-site• Authentication• Formtools• Gis• …

• Abilitare Admin-site• INSTALLED_APPS• URLS• admin.py• Python manage.py createsuperuser

Page 12: Django introduction