当前位置: 首页>>代码示例>>Python>>正文


Python QueryDict.extend方法代码示例

本文整理汇总了Python中django.http.request.QueryDict.extend方法的典型用法代码示例。如果您正苦于以下问题:Python QueryDict.extend方法的具体用法?Python QueryDict.extend怎么用?Python QueryDict.extend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.http.request.QueryDict的用法示例。


在下文中一共展示了QueryDict.extend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_url

# 需要导入模块: from django.http.request import QueryDict [as 别名]
# 或者: from django.http.request.QueryDict import extend [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
开发者ID:josuebrunel,项目名称:authentic2,代码行数:47,代码来源:utils.py


注:本文中的django.http.request.QueryDict.extend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。