Skip to content

Instantly share code, notes, and snippets.

@adamghill
Created January 29, 2014 14:02
Show Gist options
  • Save adamghill/8688581 to your computer and use it in GitHub Desktop.
Save adamghill/8688581 to your computer and use it in GitHub Desktop.
Load arbitrary content from templates without creating a ton of unnecessary view methods.
from django.http import Http404
from django.shortcuts import render_to_response
from django.template import RequestContext, TemplateDoesNotExist
def content(request, template_name):
try:
return render_to_response('content/' + template_name + '.html', {}, RequestContext(request))
except TemplateDoesNotExist:
raise Http404
from django.conf.urls import patterns, url
from .content_views import content
urlpatterns = patterns('',
url(r'^(.*?)/$', content, name='content'),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment