Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome or Safari browser. Firefox 10 and Internet Explorer 10 should also handle it.

Django
A Dgentle Introduction
Matthew Makai
August 11, 2012

Where we're going


Django

The Web framework for perfectionists with deadlines.

Django

The Web framework for perfectionists with deadlines.

Frameworks solve problems that come up repeatedly.

  1. Code organization philosophy
  2. Database access
  3. Session management
  4. Templating
  5. Encourage code reuse
  6. Authentication
Do not

How's Django different from Python?

Python = independent programming language


Django = Python framework

Model-View-Template

urls.py

from django.conf.urls.defaults import *

urlpatterns = patterns('core.views',
    url(r'^$', 'landing', name='landing_page'),
    url(r'^benefits/$', 'benefits', name='benefits'),
    url(r'^faq/$', 'faq', name='faq'),
    url(r'^contact/$', 'contact', name='contact'),
    url(r'^thanks/$', 'thanks'),
    url(r'^sign-up/', 'signUp', name="sign_up"),
)
        

views.py

from django.shortcuts import render_to_response
from django.template import RequestContext
from models import Faq

def faq(req):
    faq = Faq.objects.all()
    p = {'is_faq': True, 'faq': faq}
    if req.user.is_authenticated():
        p['is_signed_in'] = True
    return render_to_response('faq.html', p, 
        context_instance=RequestContext(req))

models.py

from django.db import models

class Faq(models.Model):
    name = models.CharField(max_length=255)
    slug = models.CharField(max_length=255, unique=True)
    question = models.CharField(max_length=255, unique=True)
    answer = models.TextField(blank=True)

Template

<html>
    <head>
        <title>Django app</title>
    </head>
    <body>
        {% for f in faq %}
            {{ f.question }}
            <p>{{ f.answer }}</p>
        {% endfor %}
    </body>
</html>
        

Model-View-Template

Questions