Schnell performante Web-Applikationen entwickeln

Werbung
Schnell performante
Web-Applikationen entwickeln
Markus Zapke-Gründemann
LinuxTag 2012
Übersicht
•
•
•
•
•
Vorstellung
Was ist Django?
Architektur
Code
Django Roadmap
•
•
•
Entwicklungsprozess
•
Nützliche Django Apps
Django in Zahlen
Django in freier
Wildbahn
Markus
Zapke-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?
Django Reinhardt
* 23.1.1910
✝ 16.5.1953
Bildquelle: http://en.wikipedia.org/wiki/File:Django_Reinhardt_%28Gottlieb_07301%29.jpg
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
Webserver
URLConf
Middleware
View
Webserver
URLConf
Middleware
View
Webserver
URLConf
Middleware
View
Model (ORM)
Webserver
URLConf
Middleware
View
Model (ORM)
Webserver
URLConf
Middleware
View
Model (ORM)
Datenbank
Webserver
URLConf
Middleware
View
Model (ORM)
Datenbank
Webserver
URLConf
Middleware
View
Model (ORM)
Datenbank
Webserver
URLConf
Middleware
View
Model (ORM)
Datenbank
Webserver
URLConf
Middleware
View
Model (ORM)
Datenbank
Template
Webserver
URLConf
Middleware
View
Model (ORM)
Datenbank
Template
Webserver
URLConf
Middleware
View
Model (ORM)
Datenbank
Template
Tags & Filter
Webserver
URLConf
Middleware
View
Model (ORM)
Datenbank
Template
Tags & Filter
Webserver
URLConf
Middleware
View
Model (ORM)
Datenbank
Template
Tags & Filter
Webserver
URLConf
Middleware
View
Model (ORM)
Datenbank
Template
Tags & Filter
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
Formulare
Admin
Validation
URLConf
Views
Templates (Tags & Filter)
Sessions
Serializer (JSON, XML,YAML)
Syndication (RSS, Atom)
GeoDjango (GIS)
Object Relational Mapper
Formulare
Admin
Validation
URLConf
File Storage
Views
Templates (Tags & Filter)
Sessions
Serializer (JSON, XML,YAML)
Syndication (RSS, Atom)
GeoDjango (GIS)
Object Relational Mapper
Formulare
Admin
Validation
URLConf
File Storage
Views
Authentifizierung
Templates (Tags & Filter)
Sessions
Serializer (JSON, XML,YAML)
Syndication (RSS, Atom)
GeoDjango (GIS)
Object Relational Mapper
Formulare
Admin
Validation
URLConf
File Storage
Views
Authentifizierung
Templates (Tags & Filter)
Testing
Sessions
Serializer (JSON, XML,YAML)
Syndication (RSS, Atom)
GeoDjango (GIS)
Object Relational Mapper
Formulare
Admin
Validation
URLConf
File Storage
Views
Authentifizierung
Templates (Tags & Filter)
Testing
Sessions
Caching
Serializer (JSON, XML,YAML)
Syndication (RSS, Atom)
GeoDjango (GIS)
Object Relational Mapper
Formulare
Admin
Validation
URLConf
File Storage
Views
Authentifizierung
Templates (Tags & Filter)
Testing
Sessions
Caching
Serializer (JSON, XML,YAML)
i18n & l10n
Syndication (RSS, Atom)
GeoDjango (GIS)
Object Relational Mapper
Formulare
Admin
Validation
URLConf
File Storage
Views
Authentifizierung
Templates (Tags & Filter)
Testing
Sessions
Caching
Serializer (JSON, XML,YAML)
i18n & l10n
Syndication (RSS, Atom)
Middleware
GeoDjango (GIS)
Object Relational Mapper
Formulare
Admin
Validation
URLConf
File Storage
Views
Authentifizierung
Templates (Tags & Filter)
Testing
Sessions
Caching
Serializer (JSON, XML,YAML)
i18n & l10n
Syndication (RSS, Atom)
Middleware
GeoDjango (GIS)
Security
Code
$ pip install django
$ pip install django
$ django-admin.py startproject myproject
$ pip install django
$ django-admin.py startproject myproject
$ tree myproject
myproject
!"" manage.py
#"" myproject
!"" __init__.py
!"" settings.py
!"" urls.py
#"" wsgi.py
$ cd myproject
$ python manage.py runserver
$ python manage.py startapp pages
$ python manage.py startapp pages
$ tree
.
!"" manage.py
!"" myproject
...
#"" pages
!"" __init__.py
!"" models.py
!"" tests.py
#"" views.py
myproject/pages/models.py
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/admin.py
from django.contrib import admin
from .models import Page
class PageAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ['title']}
admin.site.register(Page, PageAdmin)
myproject/urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
)
$ python manage.py syncdb
$ python manage.py runserver
http://127.0.0.1:8000/willkommen-auf-der-startseite/
myproject/urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('pages.urls'))
)
myproject/pages/urls.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('pages.views',
url(r'^(?P<slug>[-\w]+)/$', 'detail'),
)
myproject/pages/views.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/templates/base.html
<!doctype html>
<body>
<h1>My Website</h1>
{% block content %}{% endblock %}
</body>
</html>
myproject/pages/templates/pages/detail.html
{% extends "base.html" %}
{% block content %}
<h2>{{ object.title }}</h2>
<p>{{ object.body|linebreaks }}</p>
{% endblock %}
Django Roadmap
• Stabile API
• Minor Release alle neun Monate
• Klare Deprecation Timeline
• Ab Django 1.5 experimentelle Python 3.3
Unterstützung
Entwicklungsprozess
Deployment
Templates anlegen
Inhalte erstellen
Views anlegen
Models & Admin anlegen
Django in Zahlen
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 freier Wildbahn
ZDF - Die letzte Spur
ZDF - Die letzte Spur
Washington Post
ZDF - Die letzte Spur
Washington Post
Rdio
ZDF - Die letzte Spur
Washington Post
Rdio
Vodafone
ZDF - Die letzte Spur
Washington Post
Rdio
Vodafone
Mozilla Add-Ons
ZDF - Die letzte Spur
Washington Post
Rdio
Vodafone
Mozilla Add-Ons
Discovery Channel
ZDF - Die letzte Spur
Washington Post
Rdio
Vodafone
Mozilla Add-Ons
Discovery Channel
VMWare
ZDF - Die letzte Spur
Washington Post
Rdio
Vodafone
Mozilla Add-Ons
Discovery Channel
VMWare
Disqus
ZDF - Die letzte Spur
Washington Post
Rdio
Vodafone
Mozilla Add-Ons
Discovery Channel
VMWare
Disqus
Instagram
ZDF - Die letzte Spur
Washington Post
Rdio
Vodafone
Mozilla Add-Ons
Discovery Channel
VMWare
Disqus
Instagram
National Geographic
ZDF - Die letzte Spur
Washington Post
Rdio
Vodafone
Mozilla Add-Ons
Discovery Channel
VMWare
Disqus
Instagram
National Geographic
The 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
Herunterladen