1 | Index: core/defaulttags.py
|
---|
2 | ===================================================================
|
---|
3 | --- core/defaulttags.py (revision 854)
|
---|
4 | +++ core/defaulttags.py (working copy)
|
---|
5 | @@ -1,7 +1,9 @@
|
---|
6 | "Default tags used by the template system, available to all templates."
|
---|
7 |
|
---|
8 | +import os
|
---|
9 | import sys
|
---|
10 | import template
|
---|
11 | +import template_file
|
---|
12 |
|
---|
13 | class CommentNode(template.Node):
|
---|
14 | def render(self, context):
|
---|
15 | @@ -210,14 +212,20 @@
|
---|
16 | self.filepath, self.parsed = filepath, parsed
|
---|
17 |
|
---|
18 | def render(self, context):
|
---|
19 | - if not include_is_allowed(self.filepath):
|
---|
20 | - return '' # Fail silently for invalid includes.
|
---|
21 | - try:
|
---|
22 | - fp = open(self.filepath, 'r')
|
---|
23 | - output = fp.read()
|
---|
24 | - fp.close()
|
---|
25 | - except IOError:
|
---|
26 | - output = ''
|
---|
27 | + if not os.path.isabs(self.filepath):
|
---|
28 | + try:
|
---|
29 | + output = template_file.load_template_source(self.filepath)
|
---|
30 | + except template.TemplateDoesNotExist:
|
---|
31 | + return '' # Fail silently for non-existant templates
|
---|
32 | + else:
|
---|
33 | + if not include_is_allowed(self.filepath):
|
---|
34 | + return '' # Fail silently for invalid includes.
|
---|
35 | + try:
|
---|
36 | + fp = open(self.filepath, 'r')
|
---|
37 | + output = fp.read()
|
---|
38 | + fp.close()
|
---|
39 | + except IOError:
|
---|
40 | + output = ''
|
---|
41 | if self.parsed:
|
---|
42 | try:
|
---|
43 | t = template.Template(output)
|
---|
44 | @@ -586,11 +594,17 @@
|
---|
45 | Output the contents of a given file into the page.
|
---|
46 |
|
---|
47 | Like a simple "include" tag, the ``ssi`` tag includes the contents
|
---|
48 | - of another file -- which must be specified using an absolute page --
|
---|
49 | - in the current page::
|
---|
50 | + of another file in the current page. The file must be specified
|
---|
51 | + as either an absolute path (in which case the path must be in the
|
---|
52 | + ALLOWED_INCLUDE_ROOTS setting in settings/main.py)::
|
---|
53 |
|
---|
54 | {% ssi /home/html/ljworld.com/includes/right_generic.html %}
|
---|
55 |
|
---|
56 | + ... or as a relative path to a template file as per a call to
|
---|
57 | + template_loader.get_template()::
|
---|
58 | +
|
---|
59 | + {% ssi news/right_generic %}
|
---|
60 | +
|
---|
61 | If the optional "parsed" parameter is given, the contents of the included
|
---|
62 | file are evaluated as template code, with the current context::
|
---|
63 |
|
---|