Skip to content

Commit

Permalink
added a django template loader for embedded files
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto@debian32 committed Jul 16, 2011
1 parent e5f5f40 commit 140a1b1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions django/uwsgitemplate.py
@@ -0,0 +1,29 @@
from django.template.base import TemplateDoesNotExist
from django.template.loader import BaseLoader
from django.conf import settings

try:
import uwsgi
on_uwsgi = True
except:
on_uwsgi = False




class Loader(BaseLoader):

is_usable = on_uwsgi

def symbolize(self, name):
return name.replace('.','_').replace('/','_')

def load_template_source(self, template_name, template_dirs=None):
filename = 'templates_' + self.symbolize(template_name)
for app in settings.INSTALLED_APPS:
try:
symbol = "%s_%s" % (self.symbolize(app), filename)
return (uwsgi.embedded_data(symbol), "sym://%s" % symbol)
except:
pass
raise TemplateDoesNotExist(template_name)

0 comments on commit 140a1b1

Please sign in to comment.