SlideShare ist ein Scribd-Unternehmen logo
1 von 26
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)
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
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

Weitere ähnliche Inhalte

Was ist angesagt?

Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
Jussi Pohjolainen
 
Google
GoogleGoogle
Google
soon
 
Hi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab PresentationHi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab Presentation
plindner
 
jQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a TreejQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a Tree
adamlogic
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODM
Jonathan Wage
 

Was ist angesagt? (18)

Short intro to JQuery and Modernizr
Short intro to JQuery and ModernizrShort intro to JQuery and Modernizr
Short intro to JQuery and Modernizr
 
Google
GoogleGoogle
Google
 
JQuery
JQueryJQuery
JQuery
 
Hi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab PresentationHi5 Opensocial Code Lab Presentation
Hi5 Opensocial Code Lab Presentation
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created it
 
Drupal as a web framework
Drupal as a web frameworkDrupal as a web framework
Drupal as a web framework
 
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
Internet and Web Technology (CLASS-10) [Node.js] | NIC/NIELIT Web Technology
 
J query training
J query trainingJ query training
J query training
 
jQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a TreejQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a Tree
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Drupal Javascript for developers
Drupal Javascript for developersDrupal Javascript for developers
Drupal Javascript for developers
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on Playframework
 
Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJS
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODM
 
Doctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document MapperDoctrine MongoDB Object Document Mapper
Doctrine MongoDB Object Document Mapper
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
jQuery
jQueryjQuery
jQuery
 

Andere mochten auch

Lei organica niteroi atualizada em 2005
Lei organica  niteroi atualizada em 2005Lei organica  niteroi atualizada em 2005
Lei organica niteroi atualizada em 2005
A_dam
 
Consumidor mejora tu factura en foro genera13 nexus energia
Consumidor mejora tu factura en foro genera13   nexus energiaConsumidor mejora tu factura en foro genera13   nexus energia
Consumidor mejora tu factura en foro genera13 nexus energia
Nexus Energía S.A.
 
Aberraciones sexuales
Aberraciones sexualesAberraciones sexuales
Aberraciones sexuales
daniguzman
 

Andere mochten auch (20)

Acceso a la información online en la Universidad de Mayores de UPCT. Las asig...
Acceso a la información online en la Universidad de Mayores de UPCT. Las asig...Acceso a la información online en la Universidad de Mayores de UPCT. Las asig...
Acceso a la información online en la Universidad de Mayores de UPCT. Las asig...
 
Manual cr20.i2 - Servicio Tecnico Fagor
Manual cr20.i2 - Servicio Tecnico FagorManual cr20.i2 - Servicio Tecnico Fagor
Manual cr20.i2 - Servicio Tecnico Fagor
 
BSC_Certificate
BSC_CertificateBSC_Certificate
BSC_Certificate
 
Proyecto Nuka
Proyecto NukaProyecto Nuka
Proyecto Nuka
 
Magic eye private limited
Magic eye private limitedMagic eye private limited
Magic eye private limited
 
Presentacion egt acompañamiento
Presentacion egt acompañamientoPresentacion egt acompañamiento
Presentacion egt acompañamiento
 
Pedido partei-gomez d
Pedido partei-gomez dPedido partei-gomez d
Pedido partei-gomez d
 
Lei organica niteroi atualizada em 2005
Lei organica  niteroi atualizada em 2005Lei organica  niteroi atualizada em 2005
Lei organica niteroi atualizada em 2005
 
Lebenslanges Lernen in Web 2.0-Communities
Lebenslanges Lernen in Web 2.0-CommunitiesLebenslanges Lernen in Web 2.0-Communities
Lebenslanges Lernen in Web 2.0-Communities
 
Boletín Gente emi #43 Edición Especial
Boletín Gente emi #43 Edición EspecialBoletín Gente emi #43 Edición Especial
Boletín Gente emi #43 Edición Especial
 
Using Custom Fields For Fun And Profit
Using Custom Fields For Fun And ProfitUsing Custom Fields For Fun And Profit
Using Custom Fields For Fun And Profit
 
David guetta musica
David guetta musica David guetta musica
David guetta musica
 
KA_May_29_2015
KA_May_29_2015KA_May_29_2015
KA_May_29_2015
 
Guía de uso avanzado de PubMed
Guía de uso avanzado de PubMedGuía de uso avanzado de PubMed
Guía de uso avanzado de PubMed
 
Perspectiva legal de los negocios en Brasil
Perspectiva legal de los negocios en BrasilPerspectiva legal de los negocios en Brasil
Perspectiva legal de los negocios en Brasil
 
Email marketing - TIC 2014
Email marketing - TIC 2014Email marketing - TIC 2014
Email marketing - TIC 2014
 
Retail del Futuro: Los principales retos y desafíos del Comercio Minorista en...
Retail del Futuro: Los principales retos y desafíos del Comercio Minorista en...Retail del Futuro: Los principales retos y desafíos del Comercio Minorista en...
Retail del Futuro: Los principales retos y desafíos del Comercio Minorista en...
 
Consumidor mejora tu factura en foro genera13 nexus energia
Consumidor mejora tu factura en foro genera13   nexus energiaConsumidor mejora tu factura en foro genera13   nexus energia
Consumidor mejora tu factura en foro genera13 nexus energia
 
Aberraciones sexuales
Aberraciones sexualesAberraciones sexuales
Aberraciones sexuales
 
5 Dinge die Dr. Julian Hosp von Tony Robbins gelernt hat
5 Dinge die Dr. Julian Hosp von Tony Robbins gelernt hat5 Dinge die Dr. Julian Hosp von Tony Robbins gelernt hat
5 Dinge die Dr. Julian Hosp von Tony Robbins gelernt hat
 

Ähnlich wie Django at the Disco

An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
Gavin Roy
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
Yared Ayalew
 
How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
Will Norris
 
Templates
TemplatesTemplates
Templates
soon
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
Jacob Kaplan-Moss
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
fool2nd
 

Ähnlich wie Django at the Disco (20)

Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
GDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App EngineGDG Addis - An Introduction to Django and App Engine
GDG Addis - An Introduction to Django and App Engine
 
How Not to Build a WordPress Plugin
How Not to Build a WordPress PluginHow Not to Build a WordPress Plugin
How Not to Build a WordPress Plugin
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Templates
TemplatesTemplates
Templates
 
J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012J query b_dotnet_ug_meet_12_may_2012
J query b_dotnet_ug_meet_12_may_2012
 
WordPress for developers - phpday 2011
WordPress for developers -  phpday 2011WordPress for developers -  phpday 2011
WordPress for developers - phpday 2011
 
Django crush course
Django crush course Django crush course
Django crush course
 
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
jQuery Makes Writing JavaScript Fun Again (for HTML5 User Group)
 
The new static resources framework
The new static resources frameworkThe new static resources framework
The new static resources framework
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2Build powerfull and smart web applications with Symfony2
Build powerfull and smart web applications with Symfony2
 
Tornadoweb
TornadowebTornadoweb
Tornadoweb
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmers
 
Mobile themes, QR codes, and shortURLs
Mobile themes, QR codes, and shortURLsMobile themes, QR codes, and shortURLs
Mobile themes, QR codes, and shortURLs
 

Mehr von Richard Leland (7)

Living in harmony - a brief into to ES6
Living in harmony - a brief into to ES6Living in harmony - a brief into to ES6
Living in harmony - a brief into to ES6
 
Celery: The Distributed Task Queue
Celery: The Distributed Task QueueCelery: The Distributed Task Queue
Celery: The Distributed Task Queue
 
django-district October
django-district Octoberdjango-district October
django-district October
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
Django District April
Django District AprilDjango District April
Django District April
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

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)
  • 8.
  • 9.
  • 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
  • 21.
  • 22.
  • 23.
  • 24.
  • 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