Ticket #500: optional_template_file_extensions.diff

File optional_template_file_extensions.diff, 3.3 KB (added by Chris Beaven, 19 years ago)

Optional template file extensions (based on Jan Rademaker's idea)

  • django/conf/global_settings.py

     
    9191# List of locations of the template source files, in search order.
    9292TEMPLATE_DIRS = ()
    9393
    94 # Extension on all templates.
     94# Default extension for templates if none is given.
    9595TEMPLATE_FILE_EXTENSION = '.html'
    9696
    9797# List of callables that know how to import templates from various sources.
  • django/core/template/loaders/app_directories.py

     
    2828app_template_dirs = tuple(app_template_dirs)
    2929
    3030def get_template_sources(template_name, template_dirs=None):
     31    if not os.path.splitext(template_name):
     32        # Only append TEMPLATE_FILE_EXTENSION if there isn't an extension already.
     33        template_name = template_name + TEMPLATE_FILE_EXTENSION
    3134    for template_dir in app_template_dirs:
    32         yield os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION
     35        yield os.path.join(template_dir, template_name)
    3336
    3437def load_template_source(template_name, template_dirs=None):
    3538    for filepath in get_template_sources(template_name, template_dirs):
  • django/core/template/loaders/eggs.py

     
    77
    88from django.core.template import TemplateDoesNotExist
    99from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION
     10import os
    1011
    1112def load_template_source(template_name, template_dirs=None):
    1213    """
     
    1516    For every installed app, it tries to get the resource (app, template_name).
    1617    """
    1718    if resource_string is not None:
    18         pkg_name = 'templates/' + template_name + TEMPLATE_FILE_EXTENSION
     19        if not os.path.splitext(template_name):
     20            # Only append TEMPLATE_FILE_EXTENSION if there isn't an extension already.
     21            template_name = template_name + TEMPLATE_FILE_EXTENSION
     22        pkg_name = 'templates/' + template_name
    1923        for app in INSTALLED_APPS:
    2024            try:
    2125                return (resource_string(app, pkg_name), 'egg:%s:%s ' % (app, pkg_name))
  • django/core/template/loaders/filesystem.py

     
    77def get_template_sources(template_name, template_dirs=None):
    88    if not template_dirs:
    99        template_dirs = TEMPLATE_DIRS
     10    if not os.path.splitext(template_name):
     11        # Only append TEMPLATE_FILE_EXTENSION if there isn't an extension already.
     12        template_name = template_name + TEMPLATE_FILE_EXTENSION
    1013    for template_dir in template_dirs:
    11         yield os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION
     14        yield os.path.join(template_dir, template_name)
    1215
    1316def load_template_source(template_name, template_dirs=None):
    1417    tried = []
Back to Top