Django’ - hpi.de fileGliederung 1. Django%– Ein%Webframework% 2. ProjekteundApps 3. Models%–...

Preview:

Citation preview

Django  „The  Web  framework  for  perfec1onists  with  deadlines  “  

Gliederung  

1.  Django  –  Ein  Webframework  

2.  Projekte  und  Apps  3.  Models  –  Datenbankbeschreibung    

4.  URLconf  –  URL  Konfigura1on  5.  Templates  –  Darstellung    

6.  Views  –  GeschäQslogik    

Django  |  Jan  Teske  |  06.  Juni  2011  

2

1.  Django  –  Ein  Webframework  

Was  ist  ein  Webframework?  

•  ‚Rahmen‘  für  Entwicklung  dynamischer  Websites  

Django  |  Jan  Teske  |  06.  Juni  2011  

3

1.  Django  –  Ein  Webframework  

Was  ist  ein  Webframework?  

Django  |  Jan  Teske  |  06.  Juni  2011  

4

def hello(environ, start_response): response_headers = [('Content-type','text/plain')] start_response('200 OK', response_headers) return ['Hello world!\n']

‚Hello world‘ mit WSGI

1.  Django  –  Ein  Webframework  

Was  ist  ein  Webframework?  

•  ‚Rahmen‘  für  Entwicklung  dynamischer  Websites  

•  Übernimmt  Kommunika1on  mit  Server-­‐Schni]stellen  

•  Features  zur  Vereinfachung  der  Webentwicklung  

Django  |  Jan  Teske  |  06.  Juni  2011  

5

1.  Django  –  Ein  Webframework  

Django  

•  Webframework  für  Python  

•  „Don‘t  repeat  yourself“  (DRY),  lose  Kopplung  •  Features  u.a:  

  Templatesprache  

  Objekt-­‐rela1onaler  Wrapper  für  Datenbanken  

  URL-­‐Dispatcher  

Django  |  Jan  Teske  |  06.  Juni  2011  

6

2.  Projekte  und  Apps  

Django  |  Jan  Teske  |  06.  Juni  2011  

7

Projekt

App 1 App 2 App 3 App 4

Settings

2.  Projekte  und  Apps  

Django  |  Jan  Teske  |  06.  Juni  2011  

8

www.myfestival.de

News Infos Shop Forum

Settings

3.  Models  -­‐  Datenbankbeschreibung  

•  models.py

Django  |  Jan  Teske  |  06.  Juni  2011  

9

Name   Genre   Origin   …  

…   …   …   …  

…   …   …   …  

…   …   …   …  

…   …   …   …  

…   …   …   …  

Band  

+  Name  +  Genre  +  Origin  +  …  

Band:

4.  URLconf  –  URL-­‐Konfigura1on  

•  urls.py

•  URL-­‐Pa]ern:    Regulärer  Ausdruck    View-­‐Funk1on  

•  foo.com/bar.cgi?page=3  

•  foo.com/bar/page/3/  

Django  |  Jan  Teske  |  06.  Juni  2011  

10

5.  Templates  -­‐  Darstellung  

•  templates-­‐Verzeichnis  

•  Block-­‐Tag:  {% for b in bands %} … {% endfor %} •  Context-­‐Variable:  {{ band.name }}

Django  |  Jan  Teske  |  06.  Juni  2011  

11

Template

Context {'band': …, 'albumList': …}

Gerendertes Template

6.  Views  -­‐  GeschäQslogik  

•  views.py

Django  |  Jan  Teske  |  06.  Juni  2011  

12

URLconf

Template Models

View Request Response

Quellen  

•  h]p://www.djangoproject.com/    h]p://docs.djangoproject.com/en/1.3/  

•  h]p://www.djangobook.com/en/2.0/  

•  h]p://en.wikipedia.org/wiki/Web_applica1on_framework  

Django  |  Jan  Teske  |  06.  Juni  2011  

13

Recommended