Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Django: Schnell performante Web-Applikationen entwicklen

Django: Schnell performante Web-Applikationen entwicklen

Django ist ein in Python geschriebenes Framework, dass die schnelle Entwicklung von Web-Applikationen ermöglicht. Dabei wird Wert auf sauberen Code und die Wiederverwendbarkeit von einzelnen Komponenten gelegt.

Die Kernkomponenten des Frameworks sind der Object-Relational-Mapper (ORM), die Views und die Template Engine. Alle diese Komponenten sowie deren Zusammenspiel mit dem Routing und der Middleware werden in diesem Vortrag vorgestellt.

Der Object-Relational-Mapper (ORM) ermöglicht einen einfachen und schnellen Zugriff auf die Datenbank. Dabei werden verschiedene Datenbanken unterstützt.

Das automatisch erzeugte Admin-Interface hilft bei der Erstellung und Bearbeitung der Daten.

Die Daten werden dann in sogenannten Views aufbereitet und mit Hilfe der Template Engine gerändert. Zur Verarbeitung von Formularen stehen mächtige Formular- und Validations-Werkzeuge zur Verfügung.

Alle URLs können leicht an die Bedürfnisse des jeweiligen Projekts angepasst werden. Das gleiche gilt auch für die Templates.

Django macht auch das Testen der eignen Applikationen einfach. Dieser Vortrag wird dies ebenfalls darstellen.

Auf der Django-Website steht eine umfangreiche englische Dokumentation zur Verfügung.

Django wird als Open Source Software unter einer BSD-Lizenz verteilt.

More Decks by Markus Zapke-Gründemann

Other Decks in Programming

Transcript

  1. Übersicht • Vorstellung • Was ist Django? • Architektur •

    Code • Django Roadmap • Entwicklungsprozess • Django in Zahlen • Django in freier Wildbahn • Nützliche Django Apps
  2. Markus Zapke-Gründemann • Softwareentwickler seit 2001 • Softwareentwicklung mit Python,

    Django und Mercurial • Selbstständig seit 2008 • Seit 2011 Geschäftsführer bei Inqbus
  3. Was ist Django? • Web Application Framework • In Python

    geschrieben • Open Source Software (BSD Lizenz) • Django Software Foundation • Umfangreiche Dokumentation • Große, freundliche Community
  4. 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
  5. MTV

  6. Object Relational Mapper Admin URLConf Views Templates (Tags & Filter)

    Sessions Serializer (JSON, XML, YAML) Syndication (RSS, Atom)
  7. Object Relational Mapper Admin URLConf Views Templates (Tags & Filter)

    Sessions Serializer (JSON, XML, YAML) Syndication (RSS, Atom) GeoDjango (GIS)
  8. Object Relational Mapper Admin URLConf Views Templates (Tags & Filter)

    Sessions Serializer (JSON, XML, YAML) Syndication (RSS, Atom) GeoDjango (GIS) Formulare
  9. Object Relational Mapper Admin URLConf Views Templates (Tags & Filter)

    Sessions Serializer (JSON, XML, YAML) Syndication (RSS, Atom) GeoDjango (GIS) Formulare Validation
  10. Object Relational Mapper Admin URLConf Views Templates (Tags & Filter)

    Sessions Serializer (JSON, XML, YAML) Syndication (RSS, Atom) GeoDjango (GIS) Formulare Validation File Storage
  11. Object Relational Mapper Admin URLConf Views Templates (Tags & Filter)

    Sessions Serializer (JSON, XML, YAML) Syndication (RSS, Atom) GeoDjango (GIS) Formulare Validation File Storage Authentifizierung
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. $ pip install django $ django-admin.py startproject myproject $ tree

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

    !"" __init__.py !"" models.py !"" tests.py #"" views.py $ python manage.py startapp pages
  19. 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
  20. 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
  21. from django.conf.urls import patterns, include, url from django.contrib import admin

    admin.autodiscover() urlpatterns = patterns('', url(r'^admin/', include(admin.site.urls)), ) myproject/urls.py
  22. 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/urls.py from django.conf.urls import patterns, include, url urlpatterns = patterns('pages.views', url(r'^(?P<slug>[-\w]+)/$', 'detail'), ) myproject/pages/urls.py
  23. 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
  24. <!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
  25. Django Roadmap • Stabile API • Minor Release alle neun

    Monate • Klare Deprecation Timeline • Ab Django 1.5 experimentelle Python 3.3 Unterstützung
  26. 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
  27. 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
  28. 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
  29. ZDF - Die letzte Spur Washington Post Rdio Vodafone Mozilla

    Add-Ons Discovery Channel VMWare Disqus
  30. ZDF - Die letzte Spur Washington Post Rdio Vodafone Mozilla

    Add-Ons Discovery Channel VMWare Disqus Instagram
  31. ZDF - Die letzte Spur Washington Post Rdio Vodafone Mozilla

    Add-Ons Discovery Channel VMWare Disqus Instagram National Geographic
  32. ZDF - Die letzte Spur Washington Post Rdio Vodafone Mozilla

    Add-Ons Discovery Channel VMWare Disqus Instagram National Geographic The New York Times