Django - The Web framework for perfectionists with deadlines

58
The Web framework for perfectionists with deadlines Markus Zapke-Gründemann Webmontag Leipzig 29.03.2010

description

Django ist ein in Python programmiertes Framework, dass die schnelle Entwicklung von Web-Applikationen ermöglicht. Dabei wird Wert auf sauberen Code und die Wiederverwendbarkeit von einzelnen Komponenten gelegt. Der Vortrag wurde beim Webmontag Leipzig im März 2010 gehalten.

Transcript of Django - The Web framework for perfectionists with deadlines

Page 1: Django - The Web framework for perfectionists with deadlines

The Web frameworkfor perfectionists with deadlines

Markus Zapke-GründemannWebmontag Leipzig 29.03.2010

Page 2: Django - The Web framework for perfectionists with deadlines

• Über mich

• Was ist Django?

• Python

• Architektur

• Django in freier Wildbahn

• Django in Deutschland

• Weiterführende Links

• DjangoCon Europe

• Workshop in Leipzig

Übersicht

Page 3: Django - The Web framework for perfectionists with deadlines

MarkusZapke-Gründemann• Softwareentwickler seit 2001

• Schwerpunkt: Web Application Development mit Python und PHP

• Django, Symfony & Zend Framework

• Freier Softwareentwickler und Berater seit 2008

• www.keimlink.de

Page 4: Django - The Web framework for perfectionists with deadlines

Was ist Django?

Page 5: Django - The Web framework for perfectionists with deadlines

Jean "Django" Reinhardt23.1.1910 - 16.5.1953

Bildquelle: http://en.wikipedia.org/wiki/File:Django9.jpg

Page 6: Django - The Web framework for perfectionists with deadlines

• Web Application Framework

• In Python geschrieben

• Open Source Software (BSD Lizenz)

• Django Software Foundation

• Umfangreiche Dokumentation

• Große, freundliche Community

Was ist Django?

Page 7: Django - The Web framework for perfectionists with deadlines

• 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

Was ist Django?

Page 8: Django - The Web framework for perfectionists with deadlines

Und natürlich Ponies!

Page 9: Django - The Web framework for perfectionists with deadlines

Ponies?

Page 10: Django - The Web framework for perfectionists with deadlines

Ponies?

Page 11: Django - The Web framework for perfectionists with deadlines

The Python logo is a trademark of the Python Software Foundation.

Page 12: Django - The Web framework for perfectionists with deadlines

Guido van Rossum begann 1989 mit der Entwicklung von Python

Bildquelle: http://commons.wikimedia.org/wiki/File:Guido_van_Rossum_OSCON_2006.jpg

Page 13: Django - The Web framework for perfectionists with deadlines

Objektorientierte Sprache

class Input(Widget): """ Base class for all <input> widgets (except type='checkbox' and type='radio', which are special). """ input_type = None # Subclasses must define this.

def render(self, name, value, attrs=None): if value is None: value = '' final_attrs = self.build_attrs(attrs, type=self.input_type, name=name) if value != '': # Only add the 'value' attribute if a value is non-empty. final_attrs['value'] = force_unicode(formats.localize_input(value)) return mark_safe(u'<input%s />' % flatatt(final_attrs))

Page 14: Django - The Web framework for perfectionists with deadlines

Große StandardbibliothekBildquelle: http://www.flickr.com/photos/jhoweaa/327651705/

Page 15: Django - The Web framework for perfectionists with deadlines

Unit TestingBildquelle: http://www.flickr.com/photos/sidelong/246816211/

Page 16: Django - The Web framework for perfectionists with deadlines

Alle Logos und Warenzeichen auf dieser Seite sind Eigentum der jeweiligen Besitzer und Lizenzhalter.

Viele Betriebssysteme

Page 17: Django - The Web framework for perfectionists with deadlines

Gutes ProgrammierwerkzeugBildquelle: http://www.flickr.com/photos/philentropist/176054470/

Page 18: Django - The Web framework for perfectionists with deadlines

Freie SoftwareBildquelle: http://www.flickr.com/photos/gagilas/3809232008/

Page 19: Django - The Web framework for perfectionists with deadlines

WSGI, FastCGI, mod_pythonBildquelle: http://www.flickr.com/photos/torkildr/3462607995/

Page 20: Django - The Web framework for perfectionists with deadlines

Architektur

Page 21: Django - The Web framework for perfectionists with deadlines

Unicode

Object RelationalMapper

Form

ular

e

Template

FilterTags

Serializer

XML JSON

Applications

View

URLConf

Admin

Valid

ator

en

YAML

Syndication

AtomRSSTe

stin

g

Cac

he

i18n

Mid

dlew

are

Full Stack Framework

PythonDatenbanken

Models

Page 22: Django - The Web framework for perfectionists with deadlines
Page 23: Django - The Web framework for perfectionists with deadlines

Webserver

Page 24: Django - The Web framework for perfectionists with deadlines

Webserver

Page 25: Django - The Web framework for perfectionists with deadlines

Webserver

URLConf

Page 26: Django - The Web framework for perfectionists with deadlines

Webserver

URLConf Middleware

Page 27: Django - The Web framework for perfectionists with deadlines

Webserver

URLConf Middleware

Page 28: Django - The Web framework for perfectionists with deadlines

View

Webserver

URLConf Middleware

Page 29: Django - The Web framework for perfectionists with deadlines

View

Webserver

URLConf Middleware

Page 30: Django - The Web framework for perfectionists with deadlines

View

Webserver

Model (ORM)

URLConf Middleware

Page 31: Django - The Web framework for perfectionists with deadlines

View

Webserver

Model (ORM)

URLConf Middleware

Page 32: Django - The Web framework for perfectionists with deadlines

View

Webserver

Datenbank

Model (ORM)

URLConf Middleware

Page 33: Django - The Web framework for perfectionists with deadlines

View

Webserver

Datenbank

Model (ORM)

URLConf Middleware

Page 34: Django - The Web framework for perfectionists with deadlines

View

Webserver

Datenbank

Template

Model (ORM)

URLConf Middleware

Page 35: Django - The Web framework for perfectionists with deadlines

View

Webserver

Datenbank

Template

Model (ORM)

URLConf Middleware

Page 36: Django - The Web framework for perfectionists with deadlines

View

Webserver

Datenbank

Template

Model (ORM)

URLConf

Tags & Filter

Middleware

Page 37: Django - The Web framework for perfectionists with deadlines

View

Webserver

Datenbank

Template

Model (ORM)

URLConf

Tags & Filter

Middleware

Page 38: Django - The Web framework for perfectionists with deadlines

from django.db import models

class Musician(models.Model): first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) instrument = models.CharField(max_length=100)

class Album(models.Model): artist = models.ForeignKey(Musician) name = models.CharField(max_length=100) release_date = models.DateField() num_stars = models.IntegerField()

Model

Page 39: Django - The Web framework for perfectionists with deadlines

URLConf

from django.conf.urls.defaults import *

extra_patterns = patterns('', url(r'reports/(?P<id>\d+)/$', 'credit.views.report', name='credit-reports'), url(r'charge/$', 'credit.views.charge', name='credit-charge'),)

urlpatterns = patterns('', url(r'^$', 'apps.main.views.homepage', name='site-homepage'), (r'^help/', include('apps.help.urls')), (r'^credit/', include(extra_patterns)),)

Page 40: Django - The Web framework for perfectionists with deadlines

View

from django.shortcuts import render_to_response, get_object_or_404

from ponyfarm.models import Farm

def farm(request, farm_id): farm = get_object_or_404(Farm, pk=farm_id) return render_to_response('ponyfarm/farm.html', {'farm': farm})

Page 41: Django - The Web framework for perfectionists with deadlines

Template<html><head> <title>{% block title %}My Pony Farm{% endblock %}</title></head><body> <h2>My Pony Farm</h2> {% block content %} {% endblock %}</body></html>

{% extends "base.html" %}{% block title %}{{ block.super }} - {{ farm.title }}{% endblock %}{% block content %} <h3>{{ farm.title }}</h3> <p>{{ farm.description|linebreaks }}</a></p> <p><a href="{% url ponyfarm_object_list %}">back to overview</a></p>{% endblock %}

Page 42: Django - The Web framework for perfectionists with deadlines

Eingebauter Webserver$ python manage.py runserverValidating models...0 errors found

Django version 1.1.1, using settings 'ponysite.settings'Development server is running at http://127.0.0.1:8000/Quit the server with CONTROL-C.[25/Mar/2010 17:48:50] "GET /admin/ HTTP/1.1" 200 1686[25/Mar/2010 17:49:04] "POST /admin/ HTTP/1.1" 302 0[25/Mar/2010 17:49:04] "GET /admin/ HTTP/1.1" 200 5674[25/Mar/2010 17:49:08] "GET /admin/auth/user/ HTTP/1.1" 200 4788[25/Mar/2010 17:49:14] "GET /admin/ HTTP/1.1" 200 5674[25/Mar/2010 17:49:17] "GET /admin/auth/user/ HTTP/1.1" 200 4788

Page 43: Django - The Web framework for perfectionists with deadlines

Admin

Page 44: Django - The Web framework for perfectionists with deadlines

Djangoin freier Wildbahn

Page 45: Django - The Web framework for perfectionists with deadlines

www.ljworld.com

Page 46: Django - The Web framework for perfectionists with deadlines

www.theonion.comBildquelle: http://twitter.com/TheOnion/status/10921296161

Page 47: Django - The Web framework for perfectionists with deadlines

www.everyblock.com

Page 48: Django - The Web framework for perfectionists with deadlines

disqus.com

Page 49: Django - The Web framework for perfectionists with deadlines

www.rapidsms.orgBildquelle: http://www.rapidsms.org/about/take-the-tour/

Page 50: Django - The Web framework for perfectionists with deadlines

filmaster.com

Page 51: Django - The Web framework for perfectionists with deadlines

trailmapping.com

Page 52: Django - The Web framework for perfectionists with deadlines

Djangoin Deutschland

Page 53: Django - The Web framework for perfectionists with deadlines

Django-EntwicklerBildquelle: http://djangopeople.net/de/

Page 54: Django - The Web framework for perfectionists with deadlines

DeutscherDjango-Verein e.V.• Gegründet im Dezember 2009

• 16 Mitglieder

• Kommunikation der Entwickler und Anwender fördern

• Weiterentwicklung von Django voran treiben

• www.django-de.org

Page 55: Django - The Web framework for perfectionists with deadlines

Weiterführende Links

• www.djangoproject.com

• www.djangobook.com/en/2.0

• djangoplugables.com

• www.djangosnippets.org

• www.python.org

• www.diveintopython.org

Page 56: Django - The Web framework for perfectionists with deadlines

DjangoCon Europe

Page 57: Django - The Web framework for perfectionists with deadlines

Python & DjangoWorkshop

• 17. April 2010

• Python: 9:00 bis 13:00 Uhr

• Django: 14:00 bis 18:00 Uhr

• Im Coworking Space „Le Space“

• Unkostenbeitrag: 10 EUR

• Anmeldung: [email protected]

Page 58: Django - The Web framework for perfectionists with deadlines

Lizenz

Dieses Werk ist unter einem Creative Commons Namensnennung-Weitergabe unter gleichen

Bedingungen 3.0 Unported Lizenzvertrag lizenziert. Um die Lizenz anzusehen, gehen Sie bitte zu

http://creativecommons.org/licenses/by-sa/3.0/ oder schicken Sie einen Brief an Creative Commons, 171 Second Street, Suite 300, San Francisco, California

94105, USA.

Django is a registered trademark of the Django Software Foundation.