diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 0db77f1..17990ab 100644
--- a/django/template/defaulttags.py
+++ b/django/template/defaulttags.py
@@ -1085,7 +1085,11 @@ def url(parser, token):
     This is a way to define links that aren't tied to a particular URL
     configuration::
 
-        {% url path.to.some_view arg1,arg2,name1=value1 %}
+        {% url path.to.some_view arg1,arg2 %}
+        
+        or
+        
+        {% url path.to.some_view name1=value1,name2=value2 %}
 
     The first argument is a path to a view. It can be an absolute python path
     or just ``app_name.view_name`` without the project name if the view is
@@ -1117,27 +1121,26 @@ def url(parser, token):
     args = []
     kwargs = {}
     asvar = None
-
-    if len(bits) > 2:
-        bits = iter(bits[2:])
-        for bit in bits:
-            if bit == 'as':
-                asvar = bits.next()
-                break
+    bits = bits[2:]
+    if len(bits) >= 2 and bits[-2] == 'as':
+        asvar = bits[-1]
+        bits = bits[:-2]
+    
+    if len(bits):
+        url_args = ''.join(bits)
+        end = 0
+        for i, match in enumerate(url_arg_re.finditer(url_args)):
+            if (i == 0 and match.start() != 0) or \
+                  (i > 0 and (url_args[end:match.start()] != ',')):
+                raise TemplateSyntaxError("Malformed arguments to url tag")
+            end = match.end()
+            name, value = match.group(1), match.group(2)
+            if name:
+                kwargs[name] = parser.compile_filter(value)
             else:
-                end = 0
-                for i, match in enumerate(url_arg_re.finditer(bit)):
-                    if (i == 0 and match.start() != 0) or \
-                          (i > 0 and (bit[end:match.start()] != ',')):
-                        raise TemplateSyntaxError("Malformed arguments to url tag")
-                    end = match.end()
-                    name, value = match.group(1), match.group(2)
-                    if name:
-                        kwargs[name] = parser.compile_filter(value)
-                    else:
-                        args.append(parser.compile_filter(value))
-                if end != len(bit):
-                    raise TemplateSyntaxError("Malformed arguments to url tag")
+                args.append(parser.compile_filter(value))
+        if end != len(url_args):
+            raise TemplateSyntaxError("Malformed arguments to url tag")
 
     return URLNode(viewname, args, kwargs, asvar)
 url = register.tag(url)
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 307fecc..ec400d7 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -1033,7 +1033,10 @@ class Templates(unittest.TestCase):
             'url10': ('{% url regressiontests.templates.views.client_action id=client.id,action="two words" %}', {'client': {'id': 1}}, '/url_tag/client/1/two%20words/'),
             'url11': ('{% url regressiontests.templates.views.client_action id=client.id,action="==" %}', {'client': {'id': 1}}, '/url_tag/client/1/==/'),
             'url12': ('{% url regressiontests.templates.views.client_action id=client.id,action="," %}', {'client': {'id': 1}}, '/url_tag/client/1/,/'),
-            '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/'),
+            '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/'),
+            '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/'),
+            'url15': ('{% url regressiontests.templates.views.client_action client.id, arg|join:"-" %}', {'client': {'id': 1}, 'arg':['a','b']}, '/url_tag/client/1/a-b/'),
+            'url16': ('{% url regressiontests.templates.views.client_action 12, "test" %}', {}, '/url_tag/client/12/test/'),
 
             # Failures
             'url-fail01': ('{% url %}', {}, template.TemplateSyntaxError),
