Ticket #500: template_file_extensions_diff

File template_file_extensions_diff, 2.0 KB (added by janc@…, 19 years ago)

a small diff to implement changes that seems to allow for this, but might need more testing :)

Line 
1Index: django/conf/global_settings.py
2===================================================================
3--- django/conf/global_settings.py (revision 639)
4+++ django/conf/global_settings.py (working copy)
5@@ -51,6 +51,11 @@
6 # List of locations of the template source files, in search order.
7 TEMPLATE_DIRS = ()
8
9+# File extensions added to template names when doing something like {% extends "blah" %}.
10+TEMPLATE_FILE_EXTENSIONS = (
11+ ".html",
12+)
13+
14 # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
15 # trailing slash.
16 # Examples: "http://foo.com/media/", "/media/".
17Index: django/core/template_file.py
18===================================================================
19--- django/core/template_file.py (revision 639)
20+++ django/core/template_file.py (working copy)
21@@ -1,20 +1,21 @@
22 "Wrapper for loading templates from files"
23-from django.conf.settings import TEMPLATE_DIRS
24+from django.conf.settings import TEMPLATE_DIRS, TEMPLATE_FILE_EXTENSIONS
25 from template import TemplateDoesNotExist
26 import os
27
28-TEMPLATE_FILE_EXTENSION = '.html'
29-
30 def load_template_source(template_name, template_dirs=None):
31+ if not TEMPLATE_FILE_EXTENSIONS:
32+ raise TemplateDoesNotExist, "Your TEMPLATE_FILE_EXTENSIONS settings is empty. Change it to include at least one template file extension (an empty string is allowed)."
33 if not template_dirs:
34 template_dirs = TEMPLATE_DIRS
35 tried = []
36 for template_dir in template_dirs:
37- filepath = os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION
38- try:
39- return open(filepath).read()
40- except IOError:
41- tried.append(filepath)
42+ for template_ext in TEMPLATE_FILE_EXTENSIONS:
43+ filepath = os.path.join(template_dir, template_name) + template_ext
44+ try:
45+ return open(filepath).read()
46+ except IOError:
47+ tried.append(filepath)
48 if template_dirs:
49 error_msg = "Tried %s" % tried
50 else:
Back to Top