Skip to content

Instantly share code, notes, and snippets.

@jacobian
Created March 9, 2010 20:18
Show Gist options
  • Save jacobian/327064 to your computer and use it in GitHub Desktop.
Save jacobian/327064 to your computer and use it in GitHub Desktop.
##### yabl/settings.py
ROOT_URLCONF = 'yabl.urls'
TEMPLATE_DIRS = (
"/Users/jacob/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'^admin/', include(admin.site.urls)),
)
#### yabl/authors/urls.py
from django.conf.urls.defaults import *
urlpatterns = patterns('yabl.authors.views',
(r'^$', 'author_list'),
(r'^(\d+)/$', 'author_detail'),
)
#### yabl/authors/views.py
from django.http import HttpResponse
from django.shortcuts import render_to_response, get_object_or_404
from yabl.authors.models import Author
def author_list(request):
authors = Author.objects.all()
return render_to_response(
"authors/list.html",
{"authors": authors},
)
def author_detail(request, author_id):
author = get_object_or_404(Author, id=author_id)
return render_to_response(
"authors/detail.html",
{"author": author}
)
#### yabl/templates/authors/list.html
<html>
<head>
<title>Author list</title>
</head>
<body>
<h1>Author list:</h1>
<ul>
{% for author in authors %}
<li>{{ author.last_name }}, {{ author.first_name }}</li>
{% endfor %}
</ul>
</body>
#### yabl/templates/authors/detail.html
<html>
<head>
<title>{{ author }}</title>
</head>
<body>
<h1>{{ author }}</h1>
<p>{{ author.bio }}</p>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment