The Django Web Framework (EuroPython 2006)
Upcoming SlideShare
Loading in...5
×
 

The Django Web Framework (EuroPython 2006)

on

  • 2,343 views

I just found this old presentation, and thought it was interesting as something I put together only a year after Django's first release.

I just found this old presentation, and thought it was interesting as something I put together only a year after Django's first release.

Statistics

Views

Total Views
2,343
Views on SlideShare
2,294
Embed Views
49

Actions

Likes
1
Downloads
50
Comments
0

3 Embeds 49

http://sdlwebdevcd.ams.dev 22
http://lanyrd.com 16
http://localhost 11

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

The Django Web Framework (EuroPython 2006) The Django Web Framework (EuroPython 2006) Presentation Transcript

  • The Django Web FrameworkSimon Willisonhttp://simonwillison.net/EuroPython, 3rd July 2006
  • Web development onJournalism deadlines
  • ... in three days
  • Characteristics Clean URLs Loosely coupled components Designer-friendly templates Less code Really fast development
  • Components
  • URL dispatching
  • http://www.example.com/poll/5/ What code shall we execute?
  • (r^$, views.index),(r^hello/$, ‘views.hello),(r^poll/(d+)/$, ‘views.poll),
  • Views
  • def index(request): s = "Hello, World" return HttpResponse(s)
  • def index(request): name = request.GET[name] s = "Hi, " + escape(name) return HttpResponse(s)
  • Models
  • ...(r^poll/(d+)/$, views.poll),...
  • ...(r^poll/(d+)/$, views.poll),...def poll(request, poll_id): poll = Poll.objects.get( pk=poll_id ) return HttpResponse( Question: + poll.question )
  • class Poll(Model): question = CharField(maxlength=200) pub_date = DateTimeField()class Choice(Model): poll = ForeignKey(Poll) choice = CharField(maxlength=200) votes = IntegerField()
  • BEGIN;CREATE TABLE "polls_poll" ( "id" serial NOT NULL PRIMARY KEY, "question" varchar(200) NOT NULL, "pub_date" timestamp with time zone NOT NULL);CREATE TABLE "polls_choice" ( "id" serial NOT NULL PRIMARY KEY, "poll_id" integer NOT NULL REFERENCES "polls_polls" ("id"), "choice" varchar(200) NOT NULL, "votes" integer NOT NULL);COMMIT;
  • p = Poll( question = "Whats up?", pub_date = datetime.now())p.save()p.choice_set.create( choice = "Some choice", votes = 0)
  • >>> p.id1>>> p.question"Whats up?">>> p.choice_set.all()[<Choice: Some choice>]
  • >>> Poll.objects.count()7>>> Poll.objects.filter( pub_date__year = 2006, pub_date__month = 5)["Whats up?"]>>> Poll.objects.all()[0:2]["Whats up", "Like Django?"]
  • Templates
  • Gluing strings together gets old fast
  • c = Context({ today: datetime.date.today(), edibles: [pear, apple, orange]})
  • <h1>Hello World!</h1><p>Today is {{ today|date:"jS F, Y" }}</p>{% if edibles %}<ul> {% for fruit in edibles %} <li>{{ fruit }}</li> {% endfor %}</ul>{% endif %}
  • <h1>Hello World!</h1><p>Today is 2nd July, 2006</p><ul> <li>pear</li> <li>apple</li> <li>orange</li></ul>
  • def hello(request): return render_to_response(hello.html,{ today: datetime.date.today(), edibles: [pear, apple, orange] })
  • Common headers and footers?
  • Template inheritance
  • base.html<html><head><title> {% block title %}{% endblock %}</title></head><body>{% block main %}{% endblock %}<div id=”footer”>{% block footer %}(c) 2006{% endblock %}</div></body></html>
  • home.html{% extends “base.html” %}{% block title %}Homepage{% endblock %}{% block main %}Main page contents goes here.{% endblock %}
  • combined<html><head><title> Homepage</title></head><body>Main page contents goes here.<div id=”footer”>(c) 2006</div></body></html>
  • Loosely coupled
  • Icing
  • Bengali Japanese Czech Dutch Welsh Norwegian Danish BrazilianGerman Romanian Greek Russian English Slovak Spanish Slovenian French Serbian Galician SwedishHebrew UkrainianIcelandic Simplified Chinese Italian Traditional Chinese
  • msgid "Usernames cannot contain the @ character."msgstr "Імя не може містити @ символ"
  • Forms are boring
  • 1. Display form2. Validate submitted data3. If errors, redisplay with: 3.1. Contextual error messages 3.2. Correct fields pre-filled4. ... do something useful!
  • Model validation rules+ the Manipulator API do all of this for you
  • The admin package does even more
  • No time to talk about... Generic views Data object serialisation Syndication framework Middleware Authentication and authorisation
  • Success stories
  • 170+ public Django-powered sites http://code.djangoproject.com/wiki/DjangoPoweredSites90+ contributors1900+ mailing list subscribers (and 900+ onthe development list)And the Journal-World have convinced threenew people to go and work in Kansas
  • Find out more
  • www.djangoproject.com