Ticket #500: template_file_extensions.diff

File template_file_extensions.diff, 4.3 KB (added by JanC, 19 years ago)

New patch based on revision 917. Not tested with all the new 'loaders' yet (e.g. I have no 'egg' to test).

  • django/conf/global_settings.py

     
    5858# List of locations of the template source files, in search order.
    5959TEMPLATE_DIRS = ()
    6060
    61 # Extension on all templates.
    62 TEMPLATE_FILE_EXTENSION = '.html'
     61# File extensions added to template names when doing something like {% extends "blah" %}.
     62TEMPLATE_FILE_EXTENSIONS = (
     63    ".html",
     64)
    6365
    6466# List of callables that know how to import templates from various sources.
    6567# See the comments in django/core/template/loader.py for interface
  • django/core/template/loaders/app_directories.py

     
    11# Wrapper for loading templates from "template" directories in installed app packages.
    22
    3 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION
     3from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSIONS
    44from django.core.template import TemplateDoesNotExist
    55import os
    66
     
    1919
    2020def load_template_source(template_name, template_dirs=None):
    2121    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
    2728    raise TemplateDoesNotExist, template_name
    2829load_template_source.is_usable = True
  • django/core/template/loaders/filesystem.py

     
    11# Wrapper for loading templates from the filesystem.
    22
    3 from django.conf.settings import TEMPLATE_DIRS, TEMPLATE_FILE_EXTENSION
     3from django.conf.settings import TEMPLATE_DIRS, TEMPLATE_FILE_EXTENSIONS
    44from django.core.template import TemplateDoesNotExist
    55import os
    66
     
    99        template_dirs = TEMPLATE_DIRS
    1010    tried = []
    1111    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)
    1718    if template_dirs:
    1819        error_msg = "Tried %s" % tried
    1920    else:
  • django/core/template/loaders/eggs.py

     
    66    resource_string = None
    77
    88from django.core.template import TemplateDoesNotExist
    9 from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION
     9from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSIONS
    1010
    1111def load_template_source(template_name, template_dirs=None):
    1212    """
     
    1515    For every installed app, it tries to get the resource (app, template_name).
    1616    """
    1717    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
    2425    raise TemplateDoesNotExist, template_name
    2526load_template_source.is_usable = resource_string is not None
Back to Top