July 11, 2011
Django Sort of Static Site Generator.
Built out on ServeLocally.org
We needed a really simple site on ServeLocally.org
We really like Django for it's template abilities, among dozens of other things.
I made a one-view django site that would render, cache and serve any of our templates.
There are no models, no DB, and you can cache with wild abandon.
from django.conf.urls.defaults import patterns, urlfrom django.conf import settingsfrom django.http import Http404from django.template import RequestContextfrom django.shortcuts import render_to_responsedef direct(request, path):try:return render_to_response("%s.html" % path[:-1], context_instance=RequestContext(request))except:raise Http404urlpatterns = patterns('',# Just for Developmenturl(r"^static/(?P<path>.*)$", "django.views.static.serve", {"document_root": settings.STATIC_ROOT}),# My New Django Wiki-Alike Thingurl(r"(?P<path>.*)", direct)
)
That's my urls.py, and my one view. It will serve any url that has an associated template, so
http://servelocally.org/
is served by
templates/.html
http://servelocally.org/about/
is served by
templates/about.html
http://servelocally.org/features/sms/
(would actually throw a 404)
but if it were real, it would be served by
templates/features/sms.html
I like it a lot, it's pretty close to github's wiki system, feel free to use it.
Full code is on Github