0
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 HttpRespo...
class Poll(Model):  question = CharField(maxlength=200)  pub_date = DateTimeField()class Choice(Model):  poll = ForeignKey...
BEGIN;CREATE TABLE "polls_poll" (    "id" serial NOT NULL PRIMARY KEY,    "question" varchar(200) NOT NULL,    "pub_date" ...
p = Poll(  question = "Whats up?",  pub_date = datetime.now())p.save()p.choice_set.create(  choice = "Some choice",  votes...
>>> 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.objec...
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>{{...
<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, o...
Common headers and    footers?
Template inheritance
base.html<html><head><title>  {% block title %}{% endblock %}</title></head><body>{% block main %}{% endblock %}<div id=”f...
home.html{% extends “base.html” %}{% block title %}Homepage{% endblock %}{% block main %}Main page contents goes here.{% e...
combined<html><head><title>  Homepage</title></head><body>Main page contents goes here.<div id=”footer”>(c) 2006</div></bo...
Loosely coupled
Icing
Bengali         Japanese Czech             Dutch  Welsh         Norwegian Danish           BrazilianGerman          Romani...
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 field...
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 ...
Success stories
170+ public Django-powered sites http://code.djangoproject.com/wiki/DjangoPoweredSites90+ contributors1900+ mailing list s...
Find out more
www.djangoproject.com
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
The Django Web Framework (EuroPython 2006)
Upcoming SlideShare
Loading in...5
×

The Django Web Framework (EuroPython 2006)

2,165

Published 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.

Published in: Technology, Design
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,165
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
61
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "The Django Web Framework (EuroPython 2006)"

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

    Clipping is a handy way to collect important slides you want to go back to later.

×