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


Python parse.urlencode方法代码示例

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


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

示例1: ping_google

# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 别名]
def ping_google(sitemap_url=None, ping_url=PING_URL):
    """
    Alerts Google that the sitemap for the current site has been updated.
    If sitemap_url is provided, it should be an absolute path to the sitemap
    for this site -- e.g., '/sitemap.xml'. If sitemap_url is not provided, this
    function will attempt to deduce it by using urlresolvers.reverse().
    """
    if sitemap_url is None:
        try:
            # First, try to get the "index" sitemap URL.
            sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.index')
        except urlresolvers.NoReverseMatch:
            try:
                # Next, try for the "global" sitemap URL.
                sitemap_url = urlresolvers.reverse('django.contrib.sitemaps.views.sitemap')
            except urlresolvers.NoReverseMatch:
                pass

    if sitemap_url is None:
        raise SitemapNotFound("You didn't provide a sitemap_url, and the sitemap URL couldn't be auto-detected.")

    if not django_apps.is_installed('django.contrib.sites'):
        raise ImproperlyConfigured("ping_google requires django.contrib.sites, which isn't installed.")
    Site = django_apps.get_model('sites.Site')
    current_site = Site.objects.get_current()
    url = "http://%s%s" % (current_site.domain, sitemap_url)
    params = urlencode({'sitemap': url})
    urlopen("%s?%s" % (ping_url, params)) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:30,代码来源:__init__.py

示例2: _created_proxy_response

# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 别名]
def _created_proxy_response(self, request, path):
        request_payload = request.body

        self.log.debug("Request headers: %s", self.request_headers)

        path = quote_plus(path.encode('utf8'), QUOTE_SAFE)
        request_url = (self.upstream + '/' if path and self.upstream[-1] != '/' else self.upstream) + path

        self.log.debug("Request URL: %s", request_url)

        if request.GET:
            get_data = encode_items(request.GET.lists())
            request_url += '?' + urlencode(get_data)
            self.log.debug("Request URL: %s", request_url)

        try:
            proxy_response = self.http.urlopen(
                request.method,
                request_url,
                redirect=False,
                retries=self.retries,
                headers=self.request_headers,
                body=request_payload,
                decode_content=False,
                preload_content=False
            )
            self.log.debug("Proxy response header: %s", proxy_response.getheaders())
        except urllib3.exceptions.HTTPError as error:
            self.log.exception(error)
            raise

        return proxy_response 
开发者ID:danpoland,项目名称:drf-reverse-proxy,代码行数:34,代码来源:views.py

示例3: ping_google

# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 别名]
def ping_google(sitemap_url=None, ping_url=PING_URL):
    """
    Alerts Google that the sitemap for the current site has been updated.
    If sitemap_url is provided, it should be an absolute path to the sitemap
    for this site -- e.g., '/sitemap.xml'. If sitemap_url is not provided, this
    function will attempt to deduce it by using urls.reverse().
    """
    sitemap_full_url = _get_sitemap_full_url(sitemap_url)
    params = urlencode({'sitemap': sitemap_full_url})
    urlopen('%s?%s' % (ping_url, params)) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:12,代码来源:__init__.py

示例4: replace_query_param

# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 别名]
def replace_query_param(url, key, val):
    """
    Given a URL and a key/val pair, set or replace an item in the query
    parameters of the URL, and return the new URL.
    """
    (scheme, netloc, path, query, fragment) = urlparse.urlsplit(force_str(url))
    query_dict = urlparse.parse_qs(query, keep_blank_values=True)
    query_dict[force_str(key)] = [force_str(val)]
    query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
    return urlparse.urlunsplit((scheme, netloc, path, query, fragment)) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:12,代码来源:urls.py

示例5: remove_query_param

# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 别名]
def remove_query_param(url, key):
    """
    Given a URL and a key/val pair, remove an item in the query
    parameters of the URL, and return the new URL.
    """
    (scheme, netloc, path, query, fragment) = urlparse.urlsplit(force_str(url))
    query_dict = urlparse.parse_qs(query, keep_blank_values=True)
    query_dict.pop(key, None)
    query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
    return urlparse.urlunsplit((scheme, netloc, path, query, fragment)) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:12,代码来源:urls.py

示例6: encode_cursor

# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 别名]
def encode_cursor(self, cursor):
        """
        Given a Cursor instance, return an url with encoded cursor.
        """
        tokens = {}
        if cursor.offset != 0:
            tokens['o'] = str(cursor.offset)
        if cursor.reverse:
            tokens['r'] = '1'
        if cursor.position is not None:
            tokens['p'] = cursor.position

        querystring = urlparse.urlencode(tokens, doseq=True)
        encoded = b64encode(querystring.encode('ascii')).decode('ascii')
        return replace_query_param(self.base_url, self.cursor_query_param, encoded) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:17,代码来源:pagination.py

示例7: replace_query_param

# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 别名]
def replace_query_param(url, key, val):
    """
    Given a URL and a key/val pair, set or replace an item in the query
    parameters of the URL, and return the new URL.
    """
    (scheme, netloc, path, query, fragment) = urlparse.urlsplit(url)
    query_dict = urlparse.parse_qs(query)
    query_dict[key] = [val]
    query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
    return urlparse.urlunsplit((scheme, netloc, path, query, fragment)) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:12,代码来源:urls.py

示例8: remove_query_param

# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urlencode [as 别名]
def remove_query_param(url, key):
    """
    Given a URL and a key/val pair, remove an item in the query
    parameters of the URL, and return the new URL.
    """
    (scheme, netloc, path, query, fragment) = urlparse.urlsplit(url)
    query_dict = urlparse.parse_qs(query)
    query_dict.pop(key, None)
    query = urlparse.urlencode(sorted(list(query_dict.items())), doseq=True)
    return urlparse.urlunsplit((scheme, netloc, path, query, fragment)) 
开发者ID:erigones,项目名称:esdc-ce,代码行数:12,代码来源:urls.py


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