SlideShare a Scribd company logo
Django at the Disco
An introduction to the Django Web framework and
how it's used by the Discovery Creative team

Rich Leland
Discovery Creative

@richleland
richard_leland@discovery.com
http://creative.discovery.com
What is           ?

• Python Web framework
• Originally developed for The World Company
• Named after jazz guitarist Django Reinhardt
• Released under BSD license in 2005
Who’s using it?

• NASA
• PBS
• Discovery
• National Geographic
• The New York Times
• Broadway
• WNYC
• Google
• LA Times
• LexisNexis
Example project structure
myproject
 __init__.py
 manage.py
 settings.py
 urls.py
 myapp
   __init__.py
   admin.py
   models.py
   urls.py
   views.py
 static
 templates
   myproject
Key Features

• Object-relational mapper
• Automatic admin interface
• Elegant, Regex-based URL design
• Template language
• Cache system
• Internationalization
• Community
Object-relational mapper
from django.db import models

class Network(models.Model):
   """
   Represents a member of our family of Networks.
   """
   visible = models.BooleanField(default=True)
   name = models.CharField(max_length=100)
   slug = models.SlugField(unique=True)
   large_logo = models.ImageField(upload_to='ugc/logos/lg/', blank=True)
   small_logo = models.ImageField(upload_to='ugc/logos/sm/', blank=True)
   link = models.URLField(verify_exists=False, blank=True)

...

# in another file, e.g. views.py:

from myapp.models import Network

Network.objects.all()
Network.objects.get(pk=5)
Network.objects.filter(slug=”some-network”)
Automatic admin interface

class NetworkAdmin(admin.ModelAdmin):
   list_display = ('name', 'admin_logo', 'link', 'visible')

     list_filter = ('visible',)

     search_fields = ('name',)
   prepopulated_fields = {
      'slug': ('name',)
   }


admin.site.register(Network, NetworkAdmin)
Django at the Disco
Django at the Disco
Elegant, RegEx-based URL design

from django.conf.urls.defaults import *

urlpatterns = patterns('',
   (r'^admin/doc/', include('django.contrib.admindocs.urls')),
   (r'^admin/(.*)', admin.site.root),

    # included url confs from other apps
    (r'^account/', include('registration.urls')),
    (r'^bookmarks/', include('bookmarks.urls')),
    (r'^messages/', include('mailer.urls')),

    # named url patterns pointing to a view
    url(r'^downloads/add/(?P<content_type_id>[d]+)/(?P<object_id>[d]+)/$',
        'pressweb.media.views.add_download',
        name='add-download'),

    url(r'^$',
       'pressweb.network.views.region_list',
       name='select-region-list'),

)
URL structure breakdown

(r'^admin/doc/', include('django.contrib.admindocs.urls')),
  RegEx pattern                  include of another urls.py




                                                         RegEx pattern
url(r'^networks/(?P<object_id>[d]+)/$',
    view='myapp.views.network_detail',                   views.py
    name='add-download'),                                pattern name
Template system

{% extends "base.html" %}
{% load i18n %}

{% block title %}Bookmarks: {% endblock %}
{% block bodyclass %}bookmarks wide{% endblock %}
{% block bodyid %}{{ network.slug }}{% endblock %}

{% block content %}
   {% if bookmarks %}
   <div class="list-view">
      {% for bookmark in bookmarks %}
      <div class="item {% cycle 'odd' 'even' %}">
         <div class="column1">{{ bookmark.created|date:"F j, Y" }}</div>
         <div class="column2">{{ bookmark.title }}</div>
         <div class="column3"><a href="{{ bookmark.url }}">Go to Page</a></div>
      </div>
      {% endfor %}
   </div>
   {% endif %}
{% endblock %}
Template system

{% extends "base.html" %}
{% load i18n %}

{% block title %}Bookmarks: {% endblock %}
{% block bodyclass %}bookmarks wide{% endblock %}
{% block bodyid %}{{ network.slug }}{% endblock %}

{% block content %}
   {% if bookmarks %}
   <div class="list-view">
     {% for bookmark in bookmarks %}
     <div class="item {% cycle 'odd' 'even' %}">
         <div class="column1">{{ bookmark.created|date:"F j, Y" }}</div>
         <div class="column2">{{ bookmark.title }}</div>
         <div class="column3"><a href="{{ bookmark.url }}">Go to Page</a></div>
     </div>
     {% endfor %}
   </div>
   {% endif %}
{% endblock %}
Cache system

Site-wide cache
MIDDLEWARE_CLASSES = (
  'django.middleware.cache.UpdateCacheMiddleware',
  'django.middleware.common.CommonMiddleware',
  'django.middleware.cache.FetchFromCacheMiddleware',
)



Per-view cache
@cache_page(60 * 15)
def my_view(request):
  ...
Cache system

Template fragment caching
{% load cache %}
{% cache 500 sidebar %}
   .. sidebar ..
{% endcache %}



Low-level cache API
from django.core.cache import cache
cache.set('my_key', 'hello, world!', 30)
cache.get('my_key')
Internationalization

i18n in templates
{% trans "Bookmarks" %}
{% blocktrans %}This object is called {{ obj.name }}{% endblocktrans %}




i18n in modules
from django.utils.translation import ugettext_lazy as _

class MyThing(models.Model):
   name = models.CharField(_('name'), help_text=_('This is the help text'))




Create message files (.po), compile them (.mo)
django-admin.py makemessages -l pt_BR
django-admin.py compilemessages
Contrib Apps

• Authentication
• Admin
• Cache
• Comments
• CSRF
• Email
• i18n
• Jython support
• Serialization
• Syndication
• GIS (GeoDjango)
Community

• Core devs actively involved
• Thousands of community-contributed apps
• IRC: #django and #django-dev
• Mailing lists: django-users and django-developers
• Twitter: @djangotracker
Discovery Creative

• In-house ad agency for Discovery and family of
 networks
• Established 1996
• 100 strong: design, dev, photo, copy, account
 services, motion, prepress, production
• Web team established 2006
 • 2 Django devs
 • 4 Designers/front-end devs
 • 2 Project managers
 • 1 QA manager
• Located in Silver Spring & London
• Service all networks and business units globally
How we’re using Django

• Rapid application development
• Combination of B2B, B2C, in-house apps (directory)
• Working with partners (Siemens, AFI/Silverdocs)
• Saving the company money: 2007: $900k, 2008:
$1.5M
Django at the Disco
Django at the Disco
Django at the Disco
Django at the Disco
Learn more

• docs.djangoproject.com
• djangobook.com
• djangosnippets.org
• Practical Django Projects
• Djangocon: Sept 8-12 in Portland
• django-district.org
Thank you!

Rich Leland
Discovery Creative

@richleland
richard_leland@discovery.com
http://creative.discovery.com

More Related Content

PDF
Django at the Disco
KEY
PHPConf-TW 2012 # Twig
PDF
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
PDF
Bag Of Tricks From Iusethis
PPTX
Simple blog wall creation on Java
PPTX
Big Data for each one of us
PDF
Django Class-based views (Slovenian)
PDF
Diving into php
Django at the Disco
PHPConf-TW 2012 # Twig
jQuery UI Widgets, Drag and Drop, Drupal 7 Javascript
Bag Of Tricks From Iusethis
Simple blog wall creation on Java
Big Data for each one of us
Django Class-based views (Slovenian)
Diving into php

What's hot (18)

PDF
Short intro to JQuery and Modernizr
KEY
Google
PPTX
PPT
Hi5 Opensocial Code Lab Presentation
PPTX
HirshHorn theme: how I created it
KEY
Drupal as a web framework
PPTX
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
PDF
jQuery and Rails, Sitting in a Tree
PDF
Building iPhone Web Apps using "classic" Domino
PPT
Drupal Javascript for developers
PDF
Symfony2 from the Trenches
PPT
Intoduction on Playframework
PDF
Opencast Admin UI - Introduction to developing using AngularJS
PDF
ZendCon2010 Doctrine MongoDB ODM
PDF
Doctrine MongoDB Object Document Mapper
PPT
JQuery introduction
PPTX
jQuery
Short intro to JQuery and Modernizr
Google
Hi5 Opensocial Code Lab Presentation
HirshHorn theme: how I created it
Drupal as a web framework
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
jQuery and Rails, Sitting in a Tree
Building iPhone Web Apps using "classic" Domino
Drupal Javascript for developers
Symfony2 from the Trenches
Intoduction on Playframework
Opencast Admin UI - Introduction to developing using AngularJS
ZendCon2010 Doctrine MongoDB ODM
Doctrine MongoDB Object Document Mapper
JQuery introduction
jQuery
Ad

Viewers also liked (15)

PDF
Jeep cherokee night eagle announced for uk
PPTX
LEÇON 19 – Je ne suis pas seul à éprouver les effets de mes pensées.
PDF
Audi partners with sirius xm for emergency services
PPTX
Risk assessments
PPTX
Chemokine receptor~
PDF
2015 MSSJ presentation_Wiggins
PPTX
Geographic Phenomena and their Representations
PDF
Ueda2016 hyperparathyroidism - mohamed mashahit
PDF
Sanierung oder Neubau von Veranstaltungshäusern – Ansätze und Vorgehensweisen...
PDF
GDPR Implications Customer Identity Management - German
PPTX
India case for deploying pos sysetms
PPTX
BIOMETRIC IDENTIFICATION IN ATM’S PPT
PPT
Bio atm with-microsoft_finger_print_sdk
PPTX
Ginecólogo oncólogo: experto cirujano en cáncer de ovario
PDF
Cáncer de ovario: tratamiento quirúrgico (cirugía) y terapéutico (quimioterap...
Jeep cherokee night eagle announced for uk
LEÇON 19 – Je ne suis pas seul à éprouver les effets de mes pensées.
Audi partners with sirius xm for emergency services
Risk assessments
Chemokine receptor~
2015 MSSJ presentation_Wiggins
Geographic Phenomena and their Representations
Ueda2016 hyperparathyroidism - mohamed mashahit
Sanierung oder Neubau von Veranstaltungshäusern – Ansätze und Vorgehensweisen...
GDPR Implications Customer Identity Management - German
India case for deploying pos sysetms
BIOMETRIC IDENTIFICATION IN ATM’S PPT
Bio atm with-microsoft_finger_print_sdk
Ginecólogo oncólogo: experto cirujano en cáncer de ovario
Cáncer de ovario: tratamiento quirúrgico (cirugía) y terapéutico (quimioterap...
Ad

Similar to Django at the Disco (20)

PDF
Django Overview
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
PPTX
The Django Web Application Framework 2
KEY
Approaches to mobile site development
PDF
Django tips & tricks
PDF
Django introduction @ UGent
PDF
The Best (and Worst) of Django
PDF
GDG Addis - An Introduction to Django and App Engine
PDF
Web Development with Python and Django
PPTX
Django Architecture Introduction
PDF
You've done the Django Tutorial, what next?
KEY
Introduction to Django
PPTX
Django Portfolio Website Workshop (1).pptx
PDF
Django Introduction & Tutorial
PPTX
Django course
PDF
Django 1.10.3 Getting started
PDF
Django - basics
PDF
Where Django Caching Bust at the Seams
Django Overview
The Django Web Application Framework 2
The Django Web Application Framework 2
The Django Web Application Framework 2
The Django Web Application Framework 2
Approaches to mobile site development
Django tips & tricks
Django introduction @ UGent
The Best (and Worst) of Django
GDG Addis - An Introduction to Django and App Engine
Web Development with Python and Django
Django Architecture Introduction
You've done the Django Tutorial, what next?
Introduction to Django
Django Portfolio Website Workshop (1).pptx
Django Introduction & Tutorial
Django course
Django 1.10.3 Getting started
Django - basics
Where Django Caching Bust at the Seams

More from Richard Leland (7)

PPTX
Living in harmony - a brief into to ES6
PDF
Celery: The Distributed Task Queue
ZIP
django-district October
ZIP
Django at the Disco
ZIP
Django at the Disco
ZIP
Django at the Disco
ZIP
Django District April
Living in harmony - a brief into to ES6
Celery: The Distributed Task Queue
django-district October
Django at the Disco
Django at the Disco
Django at the Disco
Django District April

Recently uploaded (20)

PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
KodekX | Application Modernization Development
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Cloud computing and distributed systems.
PDF
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf
Review of recent advances in non-invasive hemoglobin estimation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
MYSQL Presentation for SQL database connectivity
KodekX | Application Modernization Development
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
NewMind AI Weekly Chronicles - August'25 Week I
Advanced methodologies resolving dimensionality complications for autism neur...
NewMind AI Monthly Chronicles - July 2025
Chapter 3 Spatial Domain Image Processing.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
GamePlan Trading System Review: Professional Trader's Honest Take
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Cloud computing and distributed systems.
[발표본] 너의 과제는 클라우드에 있어_KTDS_김동현_20250524.pdf

Django at the Disco

  • 1. Django at the Disco An introduction to the Django Web framework and how it's used by the Discovery Creative team Rich Leland Discovery Creative @richleland richard_leland@discovery.com http://creative.discovery.com
  • 2. What is ? • Python Web framework • Originally developed for The World Company • Named after jazz guitarist Django Reinhardt • Released under BSD license in 2005
  • 3. Who’s using it? • NASA • PBS • Discovery • National Geographic • The New York Times • Broadway • WNYC • Google • LA Times • LexisNexis
  • 4. Example project structure myproject __init__.py manage.py settings.py urls.py myapp __init__.py admin.py models.py urls.py views.py static templates myproject
  • 5. Key Features • Object-relational mapper • Automatic admin interface • Elegant, Regex-based URL design • Template language • Cache system • Internationalization • Community
  • 6. Object-relational mapper from django.db import models class Network(models.Model): """ Represents a member of our family of Networks. """ visible = models.BooleanField(default=True) name = models.CharField(max_length=100) slug = models.SlugField(unique=True) large_logo = models.ImageField(upload_to='ugc/logos/lg/', blank=True) small_logo = models.ImageField(upload_to='ugc/logos/sm/', blank=True) link = models.URLField(verify_exists=False, blank=True) ... # in another file, e.g. views.py: from myapp.models import Network Network.objects.all() Network.objects.get(pk=5) Network.objects.filter(slug=”some-network”)
  • 7. Automatic admin interface class NetworkAdmin(admin.ModelAdmin): list_display = ('name', 'admin_logo', 'link', 'visible') list_filter = ('visible',) search_fields = ('name',) prepopulated_fields = { 'slug': ('name',) } admin.site.register(Network, NetworkAdmin)
  • 10. Elegant, RegEx-based URL design from django.conf.urls.defaults import * urlpatterns = patterns('', (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/(.*)', admin.site.root), # included url confs from other apps (r'^account/', include('registration.urls')), (r'^bookmarks/', include('bookmarks.urls')), (r'^messages/', include('mailer.urls')), # named url patterns pointing to a view url(r'^downloads/add/(?P<content_type_id>[d]+)/(?P<object_id>[d]+)/$', 'pressweb.media.views.add_download', name='add-download'), url(r'^$', 'pressweb.network.views.region_list', name='select-region-list'), )
  • 11. URL structure breakdown (r'^admin/doc/', include('django.contrib.admindocs.urls')), RegEx pattern include of another urls.py RegEx pattern url(r'^networks/(?P<object_id>[d]+)/$', view='myapp.views.network_detail', views.py name='add-download'), pattern name
  • 12. Template system {% extends "base.html" %} {% load i18n %} {% block title %}Bookmarks: {% endblock %} {% block bodyclass %}bookmarks wide{% endblock %} {% block bodyid %}{{ network.slug }}{% endblock %} {% block content %} {% if bookmarks %} <div class="list-view"> {% for bookmark in bookmarks %} <div class="item {% cycle 'odd' 'even' %}"> <div class="column1">{{ bookmark.created|date:"F j, Y" }}</div> <div class="column2">{{ bookmark.title }}</div> <div class="column3"><a href="{{ bookmark.url }}">Go to Page</a></div> </div> {% endfor %} </div> {% endif %} {% endblock %}
  • 13. Template system {% extends "base.html" %} {% load i18n %} {% block title %}Bookmarks: {% endblock %} {% block bodyclass %}bookmarks wide{% endblock %} {% block bodyid %}{{ network.slug }}{% endblock %} {% block content %} {% if bookmarks %} <div class="list-view"> {% for bookmark in bookmarks %} <div class="item {% cycle 'odd' 'even' %}"> <div class="column1">{{ bookmark.created|date:"F j, Y" }}</div> <div class="column2">{{ bookmark.title }}</div> <div class="column3"><a href="{{ bookmark.url }}">Go to Page</a></div> </div> {% endfor %} </div> {% endif %} {% endblock %}
  • 14. Cache system Site-wide cache MIDDLEWARE_CLASSES = ( 'django.middleware.cache.UpdateCacheMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.cache.FetchFromCacheMiddleware', ) Per-view cache @cache_page(60 * 15) def my_view(request): ...
  • 15. Cache system Template fragment caching {% load cache %} {% cache 500 sidebar %} .. sidebar .. {% endcache %} Low-level cache API from django.core.cache import cache cache.set('my_key', 'hello, world!', 30) cache.get('my_key')
  • 16. Internationalization i18n in templates {% trans "Bookmarks" %} {% blocktrans %}This object is called {{ obj.name }}{% endblocktrans %} i18n in modules from django.utils.translation import ugettext_lazy as _ class MyThing(models.Model): name = models.CharField(_('name'), help_text=_('This is the help text')) Create message files (.po), compile them (.mo) django-admin.py makemessages -l pt_BR django-admin.py compilemessages
  • 17. Contrib Apps • Authentication • Admin • Cache • Comments • CSRF • Email • i18n • Jython support • Serialization • Syndication • GIS (GeoDjango)
  • 18. Community • Core devs actively involved • Thousands of community-contributed apps • IRC: #django and #django-dev • Mailing lists: django-users and django-developers • Twitter: @djangotracker
  • 19. Discovery Creative • In-house ad agency for Discovery and family of networks • Established 1996 • 100 strong: design, dev, photo, copy, account services, motion, prepress, production • Web team established 2006 • 2 Django devs • 4 Designers/front-end devs • 2 Project managers • 1 QA manager • Located in Silver Spring & London • Service all networks and business units globally
  • 20. How we’re using Django • Rapid application development • Combination of B2B, B2C, in-house apps (directory) • Working with partners (Siemens, AFI/Silverdocs) • Saving the company money: 2007: $900k, 2008: $1.5M
  • 25. Learn more • docs.djangoproject.com • djangobook.com • djangosnippets.org • Practical Django Projects • Djangocon: Sept 8-12 in Portland • django-district.org
  • 26. Thank you! Rich Leland Discovery Creative @richleland richard_leland@discovery.com http://creative.discovery.com