Skip to content

Instantly share code, notes, and snippets.

@jacobian
Created March 10, 2010 14:08
Show Gist options
  • Save jacobian/327892 to your computer and use it in GitHub Desktop.
Save jacobian/327892 to your computer and use it in GitHub Desktop.
###### 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('yabl.entries.views',
(r'^$', 'index'),
(r'^([\w-]+)/', 'detail'),
)
###### yabl/entries/views.py
from django.shortcuts import render_to_response, get_object_or_404
from yabl.entries.models import Entry
def index(request):
return render_to_response(
'entries/list.html',
{'entries': Entry.objects.all()}
)
def detail(request, slug):
return render_to_response(
'entries/detail.html',
{'entry': get_object_or_404(Entry, slug=slug)}
)
###### yabl/templates/entries/list.html
<html>
<head>
<title>Entry list</title>
</head>
<body>
<h1>Entry list:</h1>
<ul>
{% for entry in entries %}
<li><a href="{{ entry.slug }}/">{{ entry.headline }}</a></li>
{% endfor %}
</ul>
</body>
##### yabl/templates/entries/detail.html
<html>
<head>
<title>{{ entry }}</title>
</head>
<body>
<h1>{{ entry.headline }}</h1>
<h2>By {{ entry.author }} on {{ entry.pub_date|date:"F j, Y" }}</h2>
<p>{{ entry.body|linebreaks }}</p>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment