Ticket #7995: url_tag_improvement.diff

File url_tag_improvement.diff, 1.6 KB (added by jrocha, 7 years ago)

the patch for this ticket

  • django/template/defaulttags.py

     
    10191019
    10201020    This is a way to define links that aren't tied to a particular URL
    10211021    configuration::
    1022 
     1022        {% url path.to.some_view arg1 arg2 name1=value1 %}
     1023    or
    10231024        {% url path.to.some_view arg1,arg2,name1=value1 %}
    10241025
    10251026    The first argument is a path to a view. It can be an absolute python path
     
    10441045
    10451046    The URL will look like ``/clients/client/123/``.
    10461047    """
    1047     bits = token.contents.split(' ', 2)
     1048    bits = token.split_contents()
    10481049    if len(bits) < 2:
    10491050        raise TemplateSyntaxError("'%s' takes at least one argument"
    10501051                                  " (path to a view)" % bits[0])
    10511052    args = []
    10521053    kwargs = {}
    1053     if len(bits) > 2:
    1054         for arg in bits[2].split(','):
    1055             if '=' in arg:
    1056                 k, v = arg.split('=', 1)
    1057                 k = k.strip()
    1058                 kwargs[k] = parser.compile_filter(v)
    1059             else:
    1060                 args.append(parser.compile_filter(arg))
     1054    bit_args = []
     1055    if len(bits) == 3:
     1056        bit_args = bits[2].split(',')
     1057    elif len(bits) > 3:
     1058                bit_args = bits[2:]
     1059    for arg in bit_args:
     1060        if '=' in arg:
     1061            k, v = arg.split('=', 1)
     1062            k = k.strip()
     1063            kwargs[k] = parser.compile_filter(v)
     1064        else:
     1065            args.append(parser.compile_filter(arg))
    10611066    return URLNode(bits[1], args, kwargs)
    10621067url = register.tag(url)
    10631068
Back to Top