SlideShare a Scribd company logo
1 of 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




url(r'^networks/(?P<object_id>[d]+)/$',         RegEx pattern
     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

More Related Content

What's hot

HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created itPaul Bearne
 
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 Ayes Chinmay
 
Drupal as a web framework
Drupal as a web frameworkDrupal as a web framework
Drupal as a web frameworkAdam Kalsey
 
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 Treeadamlogic
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuerySudar Muthu
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery EssentialsMark Rackley
 
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_2012ghnash
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do MoreRemy Sharp
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on PlayframeworkKnoldus Inc.
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMJonathan Wage
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQueryRemy Sharp
 

What's hot (18)

HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created it
 
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
 
Drupal as a web framework
Drupal as a web frameworkDrupal as a web framework
Drupal as a web framework
 
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
 
J query training
J query trainingJ query training
J query training
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
jQuery
jQueryjQuery
jQuery
 
jQuery
jQueryjQuery
jQuery
 
A Short Introduction To jQuery
A Short Introduction To jQueryA Short Introduction To jQuery
A Short Introduction To jQuery
 
jQuery
jQueryjQuery
jQuery
 
SharePoint and jQuery Essentials
SharePoint and jQuery EssentialsSharePoint and jQuery Essentials
SharePoint and jQuery Essentials
 
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
 
Write Less Do More
Write Less Do MoreWrite Less Do More
Write Less Do More
 
Intoduction on Playframework
Intoduction on PlayframeworkIntoduction on Playframework
Intoduction on Playframework
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODM
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
jQuery Best Practice
jQuery Best Practice jQuery Best Practice
jQuery Best Practice
 

Viewers also liked

django-district October
django-district Octoberdjango-district October
django-district OctoberRichard Leland
 
2009 newsletter Dubbieverità 01
2009 newsletter Dubbieverità 012009 newsletter Dubbieverità 01
2009 newsletter Dubbieverità 01Monica Amici
 
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 ES6Richard Leland
 
2009 newsletter Dubbieverità 03
2009 newsletter Dubbieverità 032009 newsletter Dubbieverità 03
2009 newsletter Dubbieverità 03Monica Amici
 
2010 newsletter Dubbieverità 01
2010 newsletter Dubbieverità 012010 newsletter Dubbieverità 01
2010 newsletter Dubbieverità 01Monica Amici
 
Chapter 6 the django admin site
Chapter 6  the django admin siteChapter 6  the django admin site
Chapter 6 the django admin site家璘 卓
 
2010 newsletter Dubbieverità 02
2010 newsletter Dubbieverità 022010 newsletter Dubbieverità 02
2010 newsletter Dubbieverità 02Monica Amici
 
Customizing the Django Admin
Customizing the Django AdminCustomizing the Django Admin
Customizing the Django AdminLincoln Loop
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
The Django Web Application Framework
The Django Web Application FrameworkThe Django Web Application Framework
The Django Web Application FrameworkSimon Willison
 

Viewers also liked (13)

django-district October
django-district Octoberdjango-district October
django-district October
 
2009 newsletter Dubbieverità 01
2009 newsletter Dubbieverità 012009 newsletter Dubbieverità 01
2009 newsletter Dubbieverità 01
 
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
 
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
 
2009 newsletter Dubbieverità 03
2009 newsletter Dubbieverità 032009 newsletter Dubbieverità 03
2009 newsletter Dubbieverità 03
 
2010 newsletter Dubbieverità 01
2010 newsletter Dubbieverità 012010 newsletter Dubbieverità 01
2010 newsletter Dubbieverità 01
 
Chapter 6 the django admin site
Chapter 6  the django admin siteChapter 6  the django admin site
Chapter 6 the django admin site
 
2010 newsletter Dubbieverità 02
2010 newsletter Dubbieverità 022010 newsletter Dubbieverità 02
2010 newsletter Dubbieverità 02
 
Customizing the Django Admin
Customizing the Django AdminCustomizing the Django Admin
Customizing the Django Admin
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
The Django Web Application Framework
The Django Web Application FrameworkThe Django Web Application Framework
The Django Web Application Framework
 

Similar to Django at the Disco

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!Eric Palakovich Carr
 
Templates
TemplatesTemplates
Templatessoon
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to TornadoGavin Roy
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction DjangoWade Austin
 
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 EngineYared Ayalew
 
How to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!David Gibbons
 
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)Doris Chen
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
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" DominoRob Bontekoe
 
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 PluginWill Norris
 
Introduction to Django
Introduction to DjangoIntroduction to Django
Introduction to DjangoJoaquim Rocha
 
Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackIgnacio Martín
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of DjangoJacob Kaplan-Moss
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 

Similar to Django at the Disco (20)

Django at the Disco
Django at the DiscoDjango at the Disco
Django at the Disco
 
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!
 
Templates
TemplatesTemplates
Templates
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
Introduction Django
Introduction DjangoIntroduction Django
Introduction Django
 
Flask – Python
Flask – PythonFlask – Python
Flask – Python
 
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 to Webpack your Django!
How to Webpack your Django!How to Webpack your Django!
How to Webpack your Django!
 
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)
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
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
 
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 to Django
Introduction to DjangoIntroduction to Django
Introduction to Django
 
Keeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and WebpackKeeping the frontend under control with Symfony and Webpack
Keeping the frontend under control with Symfony and Webpack
 
Mini Curso de Django
Mini Curso de DjangoMini Curso de Django
Mini Curso de Django
 
The Best (and Worst) of Django
The Best (and Worst) of DjangoThe Best (and Worst) of Django
The Best (and Worst) of Django
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Django crush course
Django crush course Django crush course
Django crush course
 
Mobile themes, QR codes, and shortURLs
Mobile themes, QR codes, and shortURLsMobile themes, QR codes, and shortURLs
Mobile themes, QR codes, and shortURLs
 
Tornadoweb
TornadowebTornadoweb
Tornadoweb
 

Recently uploaded

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 

Recently uploaded (20)

Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 

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 url(r'^networks/(?P<object_id>[d]+)/$', RegEx pattern 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