Skip to content

Instantly share code, notes, and snippets.

@jacobian
Created February 23, 2010 20:52
Show Gist options
  • Save jacobian/312691 to your computer and use it in GitHub Desktop.
Save jacobian/312691 to your computer and use it in GitHub Desktop.
#### settings.py
TEMPLATE_DIRS = [
"/Users/jacob/Revsys/Training/yabl/templates",
]
#### yabl/urls.py
from django.conf.urls.defaults import *
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^authors/', include('yabl.authors.urls')),
(r'^entries/', include('yabl.entries.urls')),
(r'^admin/', include(admin.site.urls)),
)
#### yabl/entries/urls.py
from django.conf.urls.defaults import *
urlpatterns = patterns('',
(r'^([^/]+)/$', 'yabl.entries.views.entry_detail'),
)
#### yabl/entries/views.py
from django.shortcuts import render_to_response
from yabl.entries.models import Entry
def entry_detail(request, slug):
return render_to_response("entries/detail.html", {
"entry": Entry.objects.get(slug=slug),
})
#### yabl/templates/entries/detail.html
<h1>{{ entry.headline }}</h1>
<p>{{ entry.body }}</p>
#### yabl/authors/urls.py
from django.conf.urls.defaults import *
urlpatterns = patterns('',
('^$', 'yabl.authors.views.author_list'),
)
#### yabl/authors/views.py
from django.shortcuts import render_to_response
from yabl.authors.models import Author
def author_list(request):
return render_to_response("authors/index.html", {
"authors": Author.objects.all(),
"title": "Author List",
})
# The manual way:
#
# from django.http import HttpResponse
# from django import template
# def author_list(request):
# authors = Author.objects.all()
# tmpl = template.loader.get_template("authors/index.html")
# ctx = template.Context({"authors": authors})
# rv = tmpl.render(ctx)
# return HttpResponse(rv)
#### yabl/templates/authors/index.html
<h1>{{ title }}</h1>
<ul>
{% for author in authors %}
<li>{{ author }}</li>
{% endfor %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment