Ticket #582: template_eggs-2.patch
File template_eggs-2.patch, 2.6 KB (added by , 19 years ago) |
---|
-
django/core/template_eggs.py
1 """Wrapper for loading templates from eggs via pkg_resources.resource_string.""" 2 3 try: 4 from pkg_resources import resource_string 5 except ImportError: 6 # python2.3 compatibility hack 7 def resource_string(*args): 8 raise AssertionError, 'pkg_resource required for template_eggs' 9 10 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION 11 from django.core.template import TemplateDoesNotExist 12 13 def load_template_source(name, dirs=None): 14 """I load templates from Python eggs via pkg_resource.resource_string. 15 16 For every install app I try to get the resource (app, name).""" 17 18 pkg_name = 'templates/' + name + TEMPLATE_FILE_EXTENSION 19 20 for app in INSTALLED_APPS: 21 try: 22 return resource_string(app, pkg_name) 23 except: 24 pass 25 26 raise TemplateDoesNotExist, name -
django/core/template_loader.py
1 1 "Wrapper for loading templates from storage of some sort (e.g. files or db)" 2 2 import template 3 from template_file import load_template_source3 from django.conf.settings import TEMPLATE_SOURCE_LOADERS 4 4 5 def load_template_source(name, dirs=None): 6 for loader in TEMPLATE_SOURCE_LOADERS: 7 try: 8 return loader(name, dirs) 9 except: 10 pass 11 raise template.TemplateDoesNotExist, name 12 5 13 class ExtendsError(Exception): 6 14 pass 7 15 -
django/conf/global_settings.py
58 58 # Extension on all templates. 59 59 TEMPLATE_FILE_EXTENSION = '.html' 60 60 61 # Callables which know how to import template sources from various 62 # sources; the expected interface is callable(name, [dirs]), where dirs 63 # is a list of directories to search instead of TEMPLATE_DIRS. 64 import template_file 65 import template_eggs 66 TEMPLATE_SOURCE_LOADERS = [ 67 template_file.load_template_source, 68 template_eggs.load_template_source, 69 ] 70 del template_file 71 del template_eggs 72 61 73 # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a 62 74 # trailing slash. 63 75 # Examples: "http://foo.com/media/", "/media/".