Ticket #500: template_file_extensions.diff
File template_file_extensions.diff, 4.3 KB (added by , 19 years ago) |
---|
-
django/conf/global_settings.py
58 58 # List of locations of the template source files, in search order. 59 59 TEMPLATE_DIRS = () 60 60 61 # Extension on all templates. 62 TEMPLATE_FILE_EXTENSION = '.html' 61 # File extensions added to template names when doing something like {% extends "blah" %}. 62 TEMPLATE_FILE_EXTENSIONS = ( 63 ".html", 64 ) 63 65 64 66 # List of callables that know how to import templates from various sources. 65 67 # See the comments in django/core/template/loader.py for interface -
django/core/template/loaders/app_directories.py
1 1 # Wrapper for loading templates from "template" directories in installed app packages. 2 2 3 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION 3 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSIONS 4 4 from django.core.template import TemplateDoesNotExist 5 5 import os 6 6 … … 19 19 20 20 def load_template_source(template_name, template_dirs=None): 21 21 for template_dir in app_template_dirs: 22 filepath = os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION 23 try: 24 return open(filepath).read() 25 except IOError: 26 pass 22 for template_ext in TEMPLATE_FILE_EXTENSIONS: 23 filepath = os.path.join(template_dir, template_name) + template_ext 24 try: 25 return open(filepath).read() 26 except IOError: 27 pass 27 28 raise TemplateDoesNotExist, template_name 28 29 load_template_source.is_usable = True -
django/core/template/loaders/filesystem.py
1 1 # Wrapper for loading templates from the filesystem. 2 2 3 from django.conf.settings import TEMPLATE_DIRS, TEMPLATE_FILE_EXTENSION 3 from django.conf.settings import TEMPLATE_DIRS, TEMPLATE_FILE_EXTENSIONS 4 4 from django.core.template import TemplateDoesNotExist 5 5 import os 6 6 … … 9 9 template_dirs = TEMPLATE_DIRS 10 10 tried = [] 11 11 for template_dir in template_dirs: 12 filepath = os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION 13 try: 14 return open(filepath).read() 15 except IOError: 16 tried.append(filepath) 12 for template_ext in TEMPLATE_FILE_EXTENSIONS: 13 filepath = os.path.join(template_dir, template_name) + template_ext 14 try: 15 return open(filepath).read() 16 except IOError: 17 tried.append(filepath) 17 18 if template_dirs: 18 19 error_msg = "Tried %s" % tried 19 20 else: -
django/core/template/loaders/eggs.py
6 6 resource_string = None 7 7 8 8 from django.core.template import TemplateDoesNotExist 9 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION 9 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSIONS 10 10 11 11 def load_template_source(template_name, template_dirs=None): 12 12 """ … … 15 15 For every installed app, it tries to get the resource (app, template_name). 16 16 """ 17 17 if resource_string is not None: 18 pkg_name = 'templates/' + template_name + TEMPLATE_FILE_EXTENSION 19 for app in INSTALLED_APPS: 20 try: 21 return resource_string(app, pkg_name) 22 except: 23 pass 18 for template_ext in TEMPLATE_FILE_EXTENSIONS: 19 pkg_name = 'templates/' + template_name + template_ext 20 for app in INSTALLED_APPS: 21 try: 22 return resource_string(app, pkg_name) 23 except: 24 pass 24 25 raise TemplateDoesNotExist, template_name 25 26 load_template_source.is_usable = resource_string is not None