Ticket #7995: url_tag_improvement.diff
File url_tag_improvement.diff, 1.6 KB (added by , 16 years ago) |
---|
-
django/template/defaulttags.py
1019 1019 1020 1020 This is a way to define links that aren't tied to a particular URL 1021 1021 configuration:: 1022 1022 {% url path.to.some_view arg1 arg2 name1=value1 %} 1023 or 1023 1024 {% url path.to.some_view arg1,arg2,name1=value1 %} 1024 1025 1025 1026 The first argument is a path to a view. It can be an absolute python path … … 1044 1045 1045 1046 The URL will look like ``/clients/client/123/``. 1046 1047 """ 1047 bits = token. contents.split(' ', 2)1048 bits = token.split_contents() 1048 1049 if len(bits) < 2: 1049 1050 raise TemplateSyntaxError("'%s' takes at least one argument" 1050 1051 " (path to a view)" % bits[0]) 1051 1052 args = [] 1052 1053 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)) 1061 1066 return URLNode(bits[1], args, kwargs) 1062 1067 url = register.tag(url) 1063 1068