Ticket #12068: 12068.diff
File 12068.diff, 3.6 KB (added by , 15 years ago) |
---|
-
django/template/defaulttags.py
1118 1118 if len(bits) > 2: 1119 1119 bits = iter(bits[2:]) 1120 1120 for bit in bits: 1121 1121 1122 if bit == 'as': 1122 asvar = bits.next() 1123 break 1124 else: 1125 for arg in bit.split(","): 1126 if '=' in arg: 1127 k, v = arg.split('=', 1) 1128 k = k.strip() 1129 kwargs[k] = parser.compile_filter(v) 1130 elif arg: 1131 args.append(parser.compile_filter(arg)) 1123 try: 1124 asvar = bits.next() 1125 1126 # "as" cannot be the argument of the 'as' keyword, because it is 1127 # ambiguous: 1128 # 1129 # {% url view as as %} 1130 # 1131 # Meaning 1. This is an 'as' variable and an incomplete 'as' clause 1132 # Meaning 2. There is a complete 'as' clause and no variables 1133 1134 if asvar == 'as': 1135 raise TemplateSyntaxError("'as' may not be used as the argument" 1136 " to an 'as' keyword") 1137 1138 # We break out of this loop once we've processed an 'as' clause 1139 break 1140 1141 except StopIteration: 1142 # An incomplete 'as' clause is an error 1143 raise TemplateSyntaxError("'as' must be followed by an argument in" 1144 " the 'url' template tag") 1145 1146 1147 for arg in bit.split(","): 1148 if '=' in arg: 1149 k, v = arg.split('=', 1) 1150 k = k.strip() 1151 kwargs[k] = parser.compile_filter(v) 1152 elif arg: 1153 args.append(parser.compile_filter(arg)) 1154 1132 1155 return URLNode(viewname, args, kwargs, asvar) 1133 1156 url = register.tag(url) 1134 1157 -
tests/regressiontests/templates/tests.py
181 181 settings.SETTINGS_MODULE = old_settings_module 182 182 settings.TEMPLATE_DEBUG = old_template_debug 183 183 184 def test_url_incomplete_as_clause(self): 185 # Regression test for #12068 186 from django.template import Template, TemplateSyntaxError 187 188 # The 'as' keyword is reserved in the url tag, and must be followed by a name 189 # (which is not 'as') 190 191 self.assertRaises(TemplateSyntaxError, Template, '{% url view as %}') 192 self.assertRaises(TemplateSyntaxError, Template, '{% url view as as %}') 193 184 194 def test_templates(self): 185 195 template_tests = self.get_template_tests() 186 196 filter_tests = filters.get_filter_tests() -
docs/ref/templates/builtins.txt
947 947 <a href="{{ the_url }}">Link to optional stuff</a> 948 948 {% endif %} 949 949 950 Note that "as" is a reserved keyword, which can't be used as a variable name or as 951 the value of ``var``, as below:: 952 953 {% url path.to.view as %} 954 {% url path.to.view as as %} 955 956 950 957 .. versionadded:: 1.1 951 958 952 959 If you'd like to retrieve a namespaced URL, specify the fully qualified name::