summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorBerker Peksag <berker.peksag@gmail.com>2013-09-16 00:51:24 +0300
committerTim Graham <timograham@gmail.com>2013-09-18 07:37:08 -0400
commit2f0566fa61e13277364e3aef338fa5c143f5a704 (patch)
tree207438ec3b7983be24dc972890dda923a9f4ee45 /docs
parent893198509e3b821a56a56e4326929e0613aad983 (diff)
Fixed #4278 -- Added a dirs parameter to a few functions to override TEMPLATE_DIRS.
* django.template.loader.get_template() * django.template.loader.select_template() * django.shortcuts.render() * django.shortcuts.render_to_response() Thanks amcnabb for the suggestion.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/templates/api.txt18
-rw-r--r--docs/releases/1.7.txt8
-rw-r--r--docs/topics/http/shortcuts.txt35
3 files changed, 57 insertions, 4 deletions
diff --git a/docs/ref/templates/api.txt b/docs/ref/templates/api.txt
index b0fc94040a..b3e49b6773 100644
--- a/docs/ref/templates/api.txt
+++ b/docs/ref/templates/api.txt
@@ -594,17 +594,31 @@ The Python API
``django.template.loader`` has two functions to load templates from files:
-.. function:: get_template(template_name)
+.. function:: get_template(template_name[, dirs])
``get_template`` returns the compiled template (a ``Template`` object) for
the template with the given name. If the template doesn't exist, it raises
``django.template.TemplateDoesNotExist``.
-.. function:: select_template(template_name_list)
+ To override the :setting:`TEMPLATE_DIRS` setting, use the ``dirs``
+ parameter. The ``dirs`` parameter may be a tuple or list.
+
+ .. versionchanged:: 1.7
+
+ The ``dirs`` parameter was added.
+
+.. function:: select_template(template_name_list[, dirs])
``select_template`` is just like ``get_template``, except it takes a list
of template names. Of the list, it returns the first template that exists.
+ To override the :setting:`TEMPLATE_DIRS` setting, use the ``dirs``
+ parameter. The ``dirs`` parameter may be a tuple or list.
+
+ .. versionchanged:: 1.7
+
+ The ``dirs`` parameter was added.
+
For example, if you call ``get_template('story_detail.html')`` and have the
above :setting:`TEMPLATE_DIRS` setting, here are the files Django will look for,
in order:
diff --git a/docs/releases/1.7.txt b/docs/releases/1.7.txt
index 685efe04b3..bd22b5513f 100644
--- a/docs/releases/1.7.txt
+++ b/docs/releases/1.7.txt
@@ -285,6 +285,14 @@ Templates
* ``TypeError`` exceptions are not longer silenced when raised during the
rendering of a template.
+* The following functions now accept a ``dirs`` parameter which is a list or
+ tuple to override :setting:`TEMPLATE_DIRS`:
+
+ * :func:`django.template.loader.get_template()`
+ * :func:`django.template.loader.select_template()`
+ * :func:`django.shortcuts.render()`
+ * :func:`django.shortcuts.render_to_response()`
+
Tests
^^^^^
diff --git a/docs/topics/http/shortcuts.txt b/docs/topics/http/shortcuts.txt
index 8a80affb2a..27e8817884 100644
--- a/docs/topics/http/shortcuts.txt
+++ b/docs/topics/http/shortcuts.txt
@@ -15,7 +15,7 @@ introduce controlled coupling for convenience's sake.
``render``
==========
-.. function:: render(request, template_name[, dictionary][, context_instance][, content_type][, status][, current_app])
+.. function:: render(request, template_name[, dictionary][, context_instance][, content_type][, status][, current_app][, dirs])
Combines a given template with a given context dictionary and returns an
:class:`~django.http.HttpResponse` object with that rendered text.
@@ -58,6 +58,13 @@ Optional arguments
:ref:`namespaced URL resolution strategy <topics-http-reversing-url-namespaces>`
for more information.
+``dirs``
+ A tuple or list of values to override the :setting:`TEMPLATE_DIRS` setting.
+
+.. versionchanged:: 1.7
+
+ The ``dirs`` parameter was added.
+
Example
-------
@@ -83,11 +90,19 @@ This example is equivalent to::
return HttpResponse(t.render(c),
content_type="application/xhtml+xml")
+If you want to override the :setting:`TEMPLATE_DIRS` setting, use the
+``dirs`` parameter::
+
+ from django.shortcuts import render
+
+ def my_view(request):
+ # View code here...
+ return render(request, 'index.html', dirs=('custom_templates',))
``render_to_response``
======================
-.. function:: render_to_response(template_name[, dictionary][, context_instance][, content_type])
+.. function:: render_to_response(template_name[, dictionary][, context_instance][, content_type][, dirs])
Renders a given template with a given context dictionary and returns an
:class:`~django.http.HttpResponse` object with that rendered text.
@@ -125,6 +140,13 @@ Optional arguments
The MIME type to use for the resulting document. Defaults to the value of
the :setting:`DEFAULT_CONTENT_TYPE` setting.
+``dirs``
+ A tuple or list of values to override the :setting:`TEMPLATE_DIRS` setting.
+
+.. versionchanged:: 1.7
+
+ The ``dirs`` parameter was added.
+
Example
-------
@@ -150,6 +172,15 @@ This example is equivalent to::
return HttpResponse(t.render(c),
content_type="application/xhtml+xml")
+If you want to override the :setting:`TEMPLATE_DIRS` setting, use the
+``dirs`` parameter::
+
+ from django.shortcuts import render_to_response
+
+ def my_view(request):
+ # View code here...
+ return render_to_response('index.html', dirs=('custom_templates',))
+
``redirect``
============