summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2007-09-21 04:00:32 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2007-09-21 04:00:32 +0000
commit2570954a9aa8ae8ad1edb6927f80b5952dfe5674 (patch)
treeb129973ff27bf27a74e19a22e6f84fbeefa497a3 /docs
parent75e462099baad442570009e376d5304b864797bc (diff)
Fixed #3453: introduced a new template variable resolution system by Brian Harring (thanks!). The upshot is that variable resolution is about 25% faster, and you should see a measurable performance increase any time you've got long or deeply nested loops.
Variable resolution has changed behind the scenes -- see the note in templates_python.txt -- but template.resolve_variable() still exists. This should be fully backwards-compatible. git-svn-id: http://code.djangoproject.com/svn/django/trunk@6399 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'docs')
-rw-r--r--docs/templates_python.txt34
1 files changed, 30 insertions, 4 deletions
diff --git a/docs/templates_python.txt b/docs/templates_python.txt
index 232f54061f..b6173ad39a 100644
--- a/docs/templates_python.txt
+++ b/docs/templates_python.txt
@@ -928,10 +928,36 @@ current context, available in the ``render`` method::
``resolve_variable`` will try to resolve ``blog_entry.date_updated`` and then
format it accordingly.
-.. note::
- The ``resolve_variable()`` function will throw a ``VariableDoesNotExist``
- exception if it cannot resolve the string passed to it in the current
- context of the page.
+.. admonition:: New in development version:
+
+ Variable resolution has changed in the development version of Django.
+ ``template.resolve_variable()`` is still available, but has been deprecated
+ in favor of a new ``template.Variable`` class. Using this class will usually
+ be more efficient than calling ``template.resolve_variable``
+
+ To use the ``Variable`` class, simply instantiate it with the name of the
+ variable to be resolved, and then call ``variable.resolve(context)``. So,
+ in the development version, the above example would be more correctly
+ written as:
+
+ .. parsed-literal::
+
+ class FormatTimeNode(template.Node):
+ def __init__(self, date_to_be_formatted, format_string):
+ self.date_to_be_formatted = **Variable(date_to_be_formatted)**
+ self.format_string = format_string
+
+ def render(self, context):
+ try:
+ actual_date = **self.date_to_be_formatted.resolve(context)**
+ return actual_date.strftime(self.format_string)
+ except template.VariableDoesNotExist:
+ return ''
+
+ Changes are highlighted in bold.
+
+Variable resolution will throw a ``VariableDoesNotExist`` exception if it cannot
+resolve the string passed to it in the current context of the page.
Shortcut for simple tags
~~~~~~~~~~~~~~~~~~~~~~~~