Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Developing with Django

Daniel Ryan
October 22, 2011

Developing with Django

A "get started" guide to Django powered websites.

Daniel Ryan

October 22, 2011
Tweet

More Decks by Daniel Ryan

Other Decks in Technology

Transcript

  1. Developing with Django
    Daniel Ryan
    http://dryan.com

    View Slide

  2. Some Background
    Lawrence Journal-World
    Ellington
    Pycon 2005



    View Slide

  3. Sites Powered by Django

    View Slide

  4. Acronyms Abound
    MTV - Model • Template • View
    DRY - Don’t Repeat Yourself
    ORM - Object-relational Mapping



    View Slide

  5. MTV vs. MVC
    Model = Model
    Template = View
    View = Controller



    View Slide

  6. Installing Django
    Check out http://dryan.com/articles/snow-leopard-64bit-
    mamp/#python
    Python
    Trunk versus Stable Release
    Third Party Libraries




    View Slide

  7. A Django Workflow
    Create a project
    Configure settings.py
    Configure urls.py
    Create the database tables




    View Slide

  8. A Django Workflow
    Create an app
    Define your models
    Create the database tables
    Define your urls
    Define your views





    View Slide

  9. Reduce, Reuse, Recycle
    direct_to_template
    redirect_to
    archive_index
    archive_year
    archive_month
    archive_week
    archive_day
    archive_today
    object_detail (date based)
    object_list
    object_detail (list based)
    create_object
    update_object
    delete_object
    Django Generic
    Views

    View Slide

  10. Django Templates
    Just like PHP, except the exact opposite
    True separation of logic and presentation
    Global templates vs. app templates
    Blocks
    Tags





    View Slide

  11. Built-in Tags
    autoescape
    block
    comment
    cycle
    debug
    extends
    filter
    firstof
    for
    for ... empty
    if
    ifchanged
    ifequal
    ifnotequal
    include
    load
    now
    regroup
    spaceless
    ssi
    templatetag
    url
    widthratio
    with

    View Slide

  12. Built-in Filters
    add
    addslashes
    capfirst
    center
    cut
    date
    default
    default_if_none
    dictsort
    dictsortreversed
    escapejs
    filesizeformat
    first
    fix_ampersands
    floatformat
    force_escape
    get_digit
    iriencode
    join
    last
    length_is
    linebreaks
    linebreaksbr
    linenumbers
    ljust
    lower
    make_list
    phone2numeric
    pluralize
    pprint
    removetags
    rjust
    safe
    safeseq
    slice
    slugify
    stringformat
    striptags
    time
    timesince
    title
    truncatewords
    truncatewords_html
    unordered_list
    upper
    urlencode
    urlize
    urlizetrunc
    wordcount
    wordwrap

    View Slide

  13. Other Freebies
    Admin site
    Authentication
    Cache system
    Conditional content
    processing
    Comments
    Content types
    Cross Site Request Forgery
    protection
    Databrowse
    E-mail (sending)
    Flatpages
    Humanize
    Internationalization
    Jython support
    “Local flavor”
    Pagination
    Redirects
    Serialization
    Sessions
    Signals
    Sitemaps
    Sites
    Syndication feeds
    (RSS/Atom)
    Unicode in Django
    Web design helpers
    django.contrib

    View Slide

  14. Resources
    http://docs.djangoproject.com
    irc://irc.freenode.net/django
    http://thisweekindjango.com/
    http://www.djangosnippets.org/
    http://code.djangoproject.com/wiki/Tutorials





    View Slide