Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.4.x] Fixed #13608 - Noted that template lookups use literal values.

Backport of 74c025d from master.
  • Loading branch information...
commit c2f1aa5a3c605927f1fb86c0d4eaa9f9067a0313 1 parent c088a42
Tim Graham authored September 01, 2012
4  docs/ref/templates/api.txt
@@ -122,6 +122,10 @@ dot in a variable name, it tries the following lookups, in this order:
122 122
 * Attribute lookup. Example: ``foo.bar``
123 123
 * List-index lookup. Example: ``foo[bar]``
124 124
 
  125
+Note that "bar" in a template expression like ``{{ foo.bar }}`` will be
  126
+interpreted as a literal string and not using the value of the variable "bar",
  127
+if one exists in the template context.
  128
+
125 129
 The template system uses the first lookup type that works. It's short-circuit
126 130
 logic. Here are a few examples::
127 131
 
16  docs/topics/templates.txt
@@ -97,6 +97,18 @@ Use a dot (``.``) to access attributes of a variable.
97 97
     * Method call
98 98
     * List-index lookup
99 99
 
  100
+    This can cause some unexpected behavior with objects that override
  101
+    dictionary lookup. For example, consider the following code snippet that
  102
+    attempts to loop over a ``collections.defaultdict``::
  103
+
  104
+        {% for k, v in defaultdict.iteritems %}
  105
+            Do something with k and v here...
  106
+        {% endfor %}
  107
+
  108
+    Because dictionary lookup happens first, that behavior kicks in and provides
  109
+    a default value instead of using the intended ``.iteritems()``
  110
+    method. In this case, consider converting to a dictionary first.
  111
+
100 112
 In the above example, ``{{ section.title }}`` will be replaced with the
101 113
 ``title`` attribute of the ``section`` object.
102 114
 
@@ -104,6 +116,10 @@ If you use a variable that doesn't exist, the template system will insert
104 116
 the value of the :setting:`TEMPLATE_STRING_IF_INVALID` setting, which is set
105 117
 to ``''`` (the empty string) by default.
106 118
 
  119
+Note that "bar" in a template expression like ``{{ foo.bar }}`` will be
  120
+interpreted as a literal string and not using the value of the variable "bar",
  121
+if one exists in the template context.
  122
+
107 123
 Filters
108 124
 =======
109 125
 

0 notes on commit c2f1aa5

Please sign in to comment.
Something went wrong with that request. Please try again.