本文整理汇总了Python中django.http.request.QueryDict.appendlist方法的典型用法代码示例。如果您正苦于以下问题:Python QueryDict.appendlist方法的具体用法?Python QueryDict.appendlist怎么用?Python QueryDict.appendlist使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.http.request.QueryDict
的用法示例。
在下文中一共展示了QueryDict.appendlist方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_url
# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import appendlist [as 别名]
def make_url(to, args=(), kwargs={}, keep_params=False, params=None,
append=None, request=None, include=None, exclude=None, fragment=None, absolute=False):
'''Build an URL from a relative or absolute path, a model instance, a view
name or view function.
If you pass a request you can ask to keep params from it, exclude some
of them or include only a subset of them.
You can set parameters or append to existing one.
'''
url = resolve_url(to, *args, **kwargs)
scheme, netloc, path, query_string, o_fragment = urlparse.urlsplit(url)
url = urlparse.urlunsplit((scheme, netloc, path, '', ''))
fragment = fragment or o_fragment
# Django < 1.6 compat, query_string is not optional
url_params = QueryDict(query_string=query_string, mutable=True)
if keep_params:
assert request is not None, 'missing request'
for key, value in request.GET.iteritems():
if exclude and key in exclude:
continue
if include and key not in include:
continue
url_params.setlist(key, request.GET.getlist(key))
if params:
for key, value in params.iteritems():
if isinstance(value, (tuple, list)):
url_params.setlist(key, value)
else:
url_params[key] = value
if append:
for key, value in append.iteritems():
if isinstance(value, (tuple, list)):
url_params.extend({key: value})
else:
url_params.appendlist(key, value)
if url_params:
url += '?%s' % url_params.urlencode(safe='/')
if fragment:
url += '#%s' % fragment
if absolute:
if request:
url = request.build_absolute_uri(url)
else:
raise TypeError('make_url() absolute cannot be used without request')
return url