Skip to content

Instantly share code, notes, and snippets.

@kezabelle
Created June 3, 2016 10:09
Show Gist options
  • Save kezabelle/d9c96542b2d48c1fbae95bcdc6fe6988 to your computer and use it in GitHub Desktop.
Save kezabelle/d9c96542b2d48c1fbae95bcdc6fe6988 to your computer and use it in GitHub Desktop.
for BPL in #django IRC
from django.template import TemplateDoesNotExist, get_template
def path_to_file(request, template_name):
# assert template_name in some_safe_list if you want.
try:
get_template(template_name)
except TemplateDoesNotExist:
return render("some_fallback.html", request, context)
return render(template_name, request, context)
urlconf_mountpoint = url(regex=r'^(?P<template_name>.+)/$', view=path_to_file, name='staticpage')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment