The Django Web Framework (EuroPython 2006)

  • 1,900 views
Uploaded on

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.

More in: Technology , Design
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,900
On Slideshare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
54
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. The Django Web FrameworkSimon Willisonhttp://simonwillison.net/EuroPython, 3rd July 2006
  • 2. Web development onJournalism deadlines
  • 3. ... in three days
  • 4. Characteristics Clean URLs Loosely coupled components Designer-friendly templates Less code Really fast development
  • 5. Components
  • 6. URL dispatching
  • 7. http://www.example.com/poll/5/ What code shall we execute?
  • 8. (r^$, views.index),(r^hello/$, ‘views.hello),(r^poll/(d+)/$, ‘views.poll),
  • 9. Views
  • 10. def index(request): s = "Hello, World" return HttpResponse(s)
  • 11. def index(request): name = request.GET[name] s = "Hi, " + escape(name) return HttpResponse(s)
  • 12. Models
  • 13. ...(r^poll/(d+)/$, views.poll),...
  • 14. ...(r^poll/(d+)/$, views.poll),...def poll(request, poll_id): poll = Poll.objects.get( pk=poll_id ) return HttpResponse( Question: + poll.question )
  • 15. class Poll(Model): question = CharField(maxlength=200) pub_date = DateTimeField()class Choice(Model): poll = ForeignKey(Poll) choice = CharField(maxlength=200) votes = IntegerField()
  • 16. 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;
  • 17. p = Poll( question = "Whats up?", pub_date = datetime.now())p.save()p.choice_set.create( choice = "Some choice", votes = 0)
  • 18. >>> p.id1>>> p.question"Whats up?">>> p.choice_set.all()[<Choice: Some choice>]
  • 19. >>> 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?"]
  • 20. Templates
  • 21. Gluing strings together gets old fast
  • 22. c = Context({ today: datetime.date.today(), edibles: [pear, apple, orange]})
  • 23. <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 %}
  • 24. <h1>Hello World!</h1><p>Today is 2nd July, 2006</p><ul> <li>pear</li> <li>apple</li> <li>orange</li></ul>
  • 25. def hello(request): return render_to_response(hello.html,{ today: datetime.date.today(), edibles: [pear, apple, orange] })
  • 26. Common headers and footers?
  • 27. Template inheritance
  • 28. 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>
  • 29. home.html{% extends “base.html” %}{% block title %}Homepage{% endblock %}{% block main %}Main page contents goes here.{% endblock %}
  • 30. combined<html><head><title> Homepage</title></head><body>Main page contents goes here.<div id=”footer”>(c) 2006</div></body></html>
  • 31. Loosely coupled
  • 32. Icing
  • 33. 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
  • 34. msgid "Usernames cannot contain the @ character."msgstr "Імя не може містити @ символ"
  • 35. Forms are boring
  • 36. 1. Display form2. Validate submitted data3. If errors, redisplay with: 3.1. Contextual error messages 3.2. Correct fields pre-filled4. ... do something useful!
  • 37. Model validation rules+ the Manipulator API do all of this for you
  • 38. The admin package does even more
  • 39. No time to talk about... Generic views Data object serialisation Syndication framework Middleware Authentication and authorisation
  • 40. Success stories
  • 41. 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
  • 42. Find out more
  • 43. www.djangoproject.com