diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 0db77f1..17990ab 100644
a
|
b
|
def url(parser, token):
|
1085 | 1085 | This is a way to define links that aren't tied to a particular URL |
1086 | 1086 | configuration:: |
1087 | 1087 | |
1088 | | {% url path.to.some_view arg1,arg2,name1=value1 %} |
| 1088 | {% url path.to.some_view arg1,arg2 %} |
| 1089 | |
| 1090 | or |
| 1091 | |
| 1092 | {% url path.to.some_view name1=value1,name2=value2 %} |
1089 | 1093 | |
1090 | 1094 | The first argument is a path to a view. It can be an absolute python path |
1091 | 1095 | or just ``app_name.view_name`` without the project name if the view is |
… |
… |
def url(parser, token):
|
1117 | 1121 | args = [] |
1118 | 1122 | kwargs = {} |
1119 | 1123 | asvar = None |
1120 | | |
1121 | | if len(bits) > 2: |
1122 | | bits = iter(bits[2:]) |
1123 | | for bit in bits: |
1124 | | if bit == 'as': |
1125 | | asvar = bits.next() |
1126 | | break |
| 1124 | bits = bits[2:] |
| 1125 | if len(bits) >= 2 and bits[-2] == 'as': |
| 1126 | asvar = bits[-1] |
| 1127 | bits = bits[:-2] |
| 1128 | |
| 1129 | if len(bits): |
| 1130 | url_args = ''.join(bits) |
| 1131 | end = 0 |
| 1132 | for i, match in enumerate(url_arg_re.finditer(url_args)): |
| 1133 | if (i == 0 and match.start() != 0) or \ |
| 1134 | (i > 0 and (url_args[end:match.start()] != ',')): |
| 1135 | raise TemplateSyntaxError("Malformed arguments to url tag") |
| 1136 | end = match.end() |
| 1137 | name, value = match.group(1), match.group(2) |
| 1138 | if name: |
| 1139 | kwargs[name] = parser.compile_filter(value) |
1127 | 1140 | else: |
1128 | | end = 0 |
1129 | | for i, match in enumerate(url_arg_re.finditer(bit)): |
1130 | | if (i == 0 and match.start() != 0) or \ |
1131 | | (i > 0 and (bit[end:match.start()] != ',')): |
1132 | | raise TemplateSyntaxError("Malformed arguments to url tag") |
1133 | | end = match.end() |
1134 | | name, value = match.group(1), match.group(2) |
1135 | | if name: |
1136 | | kwargs[name] = parser.compile_filter(value) |
1137 | | else: |
1138 | | args.append(parser.compile_filter(value)) |
1139 | | if end != len(bit): |
1140 | | raise TemplateSyntaxError("Malformed arguments to url tag") |
| 1141 | args.append(parser.compile_filter(value)) |
| 1142 | if end != len(url_args): |
| 1143 | raise TemplateSyntaxError("Malformed arguments to url tag") |
1141 | 1144 | |
1142 | 1145 | return URLNode(viewname, args, kwargs, asvar) |
1143 | 1146 | url = register.tag(url) |
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 307fecc..ec400d7 100644
a
|
b
|
class Templates(unittest.TestCase):
|
1033 | 1033 | 'url10': ('{% url regressiontests.templates.views.client_action id=client.id,action="two words" %}', {'client': {'id': 1}}, '/url_tag/client/1/two%20words/'), |
1034 | 1034 | 'url11': ('{% url regressiontests.templates.views.client_action id=client.id,action="==" %}', {'client': {'id': 1}}, '/url_tag/client/1/==/'), |
1035 | 1035 | 'url12': ('{% url regressiontests.templates.views.client_action id=client.id,action="," %}', {'client': {'id': 1}}, '/url_tag/client/1/,/'), |
1036 | | 'url12': ('{% url regressiontests.templates.views.client_action id=client.id,action=arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'), |
| 1036 | 'url13': ('{% url regressiontests.templates.views.client_action id=client.id,action=arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'), |
| 1037 | 'url14': ('{% url regressiontests.templates.views.client_action id=client.id, action=arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'), |
| 1038 | 'url15': ('{% url regressiontests.templates.views.client_action client.id, arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'), |
| 1039 | 'url16': ('{% url regressiontests.templates.views.client_action 12, "test" %}', {}, '/url_tag/client/12/test/'), |
1037 | 1040 | |
1038 | 1041 | # Failures |
1039 | 1042 | 'url-fail01': ('{% url %}', {}, template.TemplateSyntaxError), |