Schnell performante Web-Applikationen entwickeln · GeoDjango (GIS) Formulare Validation File...

Preview:

Citation preview

Schnell performanteWeb-Applikationen entwickeln

Markus Zapke-GründemannLinuxTag 2012

Übersicht• Vorstellung

• Was ist Django?

• Architektur

• Code

• Django Roadmap

• Entwicklungsprozess

• Django in Zahlen

• Django in freier Wildbahn

• Nützliche Django Apps

MarkusZapke-Gründemann

• Softwareentwickler seit 2001

• Softwareentwicklung mit Python, Django und Mercurial

• Selbstständig seit 2008

• Seit 2011 Geschäftsführer bei Inqbus

Was ist Django?

Bildquelle: http://en.wikipedia.org/wiki/File:Django_Reinhardt_%28Gottlieb_07301%29.jpg

Django Reinhardt* 23.1.1910✝ 16.5.1953

Was ist Django?

• Web Application Framework

• In Python geschrieben

• Open Source Software (BSD Lizenz)

• Django Software Foundation

• Umfangreiche Dokumentation

• Große, freundliche Community

Was ist Django?

• Rapid Development

• Loose Coupling

• Wiederverwendbare Applikationen

• Don't Repeat Yourself (DRY)

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

http://c2.com/cgi/wiki?DontRepeatYourself

www.djangoproject.com

Und natürlich Ponies!

Ponies?

Ponies?

Architektur

MTV

Webserver

Webserver

Webserver

URLConf

Webserver

URLConf Middleware

Webserver

URLConf Middleware

View

Webserver

URLConf Middleware

View

Webserver

URLConf Middleware

View

Webserver

Model (ORM)

URLConf Middleware

View

Webserver

Model (ORM)

URLConf Middleware

View

Webserver

Datenbank

Model (ORM)

URLConf Middleware

View

Webserver

Datenbank

Model (ORM)

URLConf Middleware

View

Webserver

Datenbank

Model (ORM)

URLConf Middleware

View

Webserver

Datenbank

Model (ORM)

URLConf Middleware

View

Webserver

Datenbank

TemplateModel (ORM)

URLConf Middleware

View

Webserver

Datenbank

TemplateModel (ORM)

URLConf Middleware

View

Webserver

Datenbank

TemplateModel (ORM)

URLConf

Tags & Filter

Middleware

View

Webserver

Datenbank

TemplateModel (ORM)

URLConf

Tags & Filter

Middleware

View

Webserver

Datenbank

TemplateModel (ORM)

URLConf

Tags & Filter

Middleware

View

Webserver

Datenbank

TemplateModel (ORM)

URLConf

Tags & Filter

Middleware

Object Relational Mapper

Object Relational Mapper

Admin

Object Relational Mapper

Admin

URLConf

Object Relational Mapper

Admin

URLConf

Views

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Syndication (RSS, Atom)

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Syndication (RSS, Atom)

GeoDjango (GIS)

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Syndication (RSS, Atom)

GeoDjango (GIS)

Formulare

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Syndication (RSS, Atom)

GeoDjango (GIS)

Formulare

Validation

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Syndication (RSS, Atom)

GeoDjango (GIS)

Formulare

Validation

File Storage

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Syndication (RSS, Atom)

GeoDjango (GIS)

Formulare

Validation

File Storage

Authentifizierung

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Syndication (RSS, Atom)

GeoDjango (GIS)

Formulare

Validation

File Storage

Authentifizierung

Testing

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Syndication (RSS, Atom)

GeoDjango (GIS)

Formulare

Validation

File Storage

Authentifizierung

Testing

Caching

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Syndication (RSS, Atom)

GeoDjango (GIS)

Formulare

Validation

File Storage

Authentifizierung

Testing

Caching

i18n & l10n

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Syndication (RSS, Atom)

GeoDjango (GIS)

Formulare

Validation

File Storage

Authentifizierung

Testing

Caching

i18n & l10n

Middleware

Object Relational Mapper

Admin

URLConf

Views

Templates (Tags & Filter)

Sessions

Serializer (JSON, XML, YAML)

Syndication (RSS, Atom)

GeoDjango (GIS)

Formulare

Validation

File Storage

Authentifizierung

Testing

Caching

i18n & l10n

Middleware

Security

Code

$ pip install django

$ pip install django

$ django-admin.py startproject myproject

$ pip install django

$ django-admin.py startproject myproject

$ tree myprojectmyproject!"" manage.py#"" myproject !"" __init__.py !"" settings.py !"" urls.py #"" wsgi.py

$ cd myproject$ python manage.py runserver

$ python manage.py startapp pages

$ tree.!"" manage.py!"" myproject...#"" pages !"" __init__.py !"" models.py !"" tests.py #"" views.py

$ python manage.py startapp pages

from django.db import models

class Page(models.Model): title = models.CharField(u'Titel', max_length=100) slug = models.SlugField(unique=True) body = models.TextField(u'Inhalt')

class Meta: verbose_name = u'Seite' verbose_name_plural = u'Seiten'

def __unicode__(self): return self.title

myproject/pages/models.py

from django.contrib import admin

from .models import Page

class PageAdmin(admin.ModelAdmin): prepopulated_fields = {'slug': ['title']}

admin.site.register(Page, PageAdmin)

myproject/pages/admin.py

from django.conf.urls import patterns, include, url

from django.contrib import adminadmin.autodiscover()

urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)),)

myproject/urls.py

$ python manage.py syncdb$ python manage.py runserver

http://127.0.0.1:8000/willkommen-auf-der-startseite/

from django.conf.urls import patterns, include, url

from django.contrib import adminadmin.autodiscover()

urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), url(r'^', include('pages.urls')))

myproject/urls.py

from django.conf.urls import patterns, include, url

urlpatterns = patterns('pages.views', url(r'^(?P<slug>[-\w]+)/$', 'detail'),)

myproject/pages/urls.py

from django.shortcuts import get_object_or_404, render

from .models import Page

def detail(request, slug): page = get_object_or_404(Page, slug=slug) context = {'object': page} return render(request, 'pages/detail.html', context)

myproject/pages/views.py

<!doctype html><body> <h1>My Website</h1> {% block content %}{% endblock %}</body></html>

myproject/templates/base.html

{% extends "base.html" %}

{% block content %}<h2>{{ object.title }}</h2><p>{{ object.body|linebreaks }}</p>{% endblock %}

myproject/pages/templates/pages/detail.html

Django Roadmap

• Stabile API

• Minor Release alle neun Monate

• Klare Deprecation Timeline

• Ab Django 1.5 experimentelle Python 3.3 Unterstützung

Entwicklungsprozess

Models & Admin anlegen

Inhalte erstellen Views anlegen

Deployment

Templates anlegen

Django in Zahlen

6.000.000 Besucher der Website pro Monat

Django in Zahlen

6.000.000 Besucher der Website pro Monat

21.700 Abonnenten der django-users Mailing Liste

Django in Zahlen

6.000.000 Besucher der Website pro Monat

21.700 Abonnenten der django-users Mailing Liste

> 2.000 Packages im Python Packaging Index (> 10%)

Django in Zahlen

6.000.000 Besucher der Website pro Monat

21.700 Abonnenten der django-users Mailing Liste

> 2.000 Packages im Python Packaging Index (> 10%)

33 Kern-Entwickler

Django in Zahlen

6.000.000 Besucher der Website pro Monat

21.700 Abonnenten der django-users Mailing Liste

> 2.000 Packages im Python Packaging Index (> 10%)

33 Kern-Entwickler

> 65 Übersetzungen

Django in Zahlen

Djangoin freier Wildbahn

ZDF - Die letzte Spur

ZDF - Die letzte SpurWashington Post

ZDF - Die letzte SpurWashington Post

Rdio

ZDF - Die letzte SpurWashington Post

RdioVodafone

ZDF - Die letzte SpurWashington Post

RdioVodafone

Mozilla Add-Ons

ZDF - Die letzte SpurWashington Post

RdioVodafone

Mozilla Add-OnsDiscovery Channel

ZDF - Die letzte SpurWashington Post

RdioVodafone

Mozilla Add-OnsDiscovery Channel

VMWare

ZDF - Die letzte SpurWashington Post

RdioVodafone

Mozilla Add-OnsDiscovery Channel

VMWareDisqus

ZDF - Die letzte SpurWashington Post

RdioVodafone

Mozilla Add-OnsDiscovery Channel

VMWareDisqus

Instagram

ZDF - Die letzte SpurWashington Post

RdioVodafone

Mozilla Add-OnsDiscovery Channel

VMWareDisqus

InstagramNational Geographic

ZDF - Die letzte SpurWashington Post

RdioVodafone

Mozilla Add-OnsDiscovery Channel

VMWareDisqus

InstagramNational GeographicThe New York Times

Nützliche Django Apps

Django Debug Toolbar

http://robhudson.github.com/django-debug-toolbar/

Django Debug Toolbar

http://robhudson.github.com/django-debug-toolbar/

Django Debug Toolbar

http://robhudson.github.com/django-debug-toolbar/

Schema and Data Migrations

http://south.aeracode.org/

Celery

Distributed Task Queue

http://celeryproject.org/

Modular Search

http://haystacksearch.org/

WSGI HTTP Server for UNIX

http://gunicorn.org/

www.djangopackages.com

Fragen?

www.inqbus.de

www.keimlink.de

@keimlink

Recommended