本文整理汇总了Python中django.utils.six.moves.urllib.parse.urljoin方法的典型用法代码示例。如果您正苦于以下问题:Python parse.urljoin方法的具体用法?Python parse.urljoin怎么用?Python parse.urljoin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.six.moves.urllib.parse
的用法示例。
在下文中一共展示了parse.urljoin方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_files
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urljoin [as 别名]
def get_files(root_path, cur_path, allow_types=[]):
files = []
items = os.listdir(cur_path)
for item in items:
item_fullname = os.path.join(
root_path, cur_path, item).replace("\\", "/")
if os.path.isdir(item_fullname):
files.extend(get_files(root_path, item_fullname, allow_types))
else:
ext = os.path.splitext(item_fullname)[1]
is_allow_list = (len(allow_types) == 0) or (ext in allow_types)
if is_allow_list:
files.append({
"url": urljoin(
USettings.gSettings.MEDIA_URL,
os.path.join(
os.path.relpath(cur_path, root_path), item
).replace("\\", "/")),
"mtime": os.path.getmtime(item_fullname)
})
return files
示例2: render_ui
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urljoin [as 别名]
def render_ui(self, editorID):
""" 创建button的js代码: """
return """
var btn = new UE.ui.Button({
name: uiName,
title: "%(title)s",
cssRules: "background-image:url('%(icon)s')!important;",
onclick: function() {
%(onclick)s
}
});
return btn
""" % {
"icon": urljoin(USettings.gSettings.MEDIA_URL, self.icon),
"onclick": self.onClick(),
"title": self.title
}
示例3: absolute_path
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urljoin [as 别名]
def absolute_path(self, path, prefix=None):
if path.startswith(('http://', 'https://', '/')):
return path
if prefix is None:
if settings.STATIC_URL is None:
# backwards compatibility
prefix = settings.MEDIA_URL
else:
prefix = settings.STATIC_URL
return urljoin(prefix, path)
示例4: handle_simple
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urljoin [as 别名]
def handle_simple(cls, path):
return urljoin(PrefixNode.handle_simple("STATIC_URL"), path)
示例5: url
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urljoin [as 别名]
def url(self, name):
if self.base_url is None:
raise ValueError("This file is not accessible via a URL.")
return urljoin(self.base_url, filepath_to_uri(name))
示例6: handle_simple
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urljoin [as 别名]
def handle_simple(cls, path):
if apps.is_installed('django.contrib.staticfiles'):
from django.contrib.staticfiles.storage import staticfiles_storage
return staticfiles_storage.url(path)
else:
return urljoin(PrefixNode.handle_simple("STATIC_URL"), quote(path))
示例7: _handle_redirects
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urljoin [as 别名]
def _handle_redirects(self, response, **extra):
"Follows any redirects by requesting responses from the server using GET."
response.redirect_chain = []
while response.status_code in (301, 302, 303, 307):
response_url = response.url
redirect_chain = response.redirect_chain
redirect_chain.append((response_url, response.status_code))
url = urlsplit(response_url)
if url.scheme:
extra['wsgi.url_scheme'] = url.scheme
if url.hostname:
extra['SERVER_NAME'] = url.hostname
if url.port:
extra['SERVER_PORT'] = str(url.port)
# Prepend the request path to handle relative path redirects
path = url.path
if not path.startswith('/'):
path = urljoin(response.request['PATH_INFO'], path)
response = self.get(path, QueryDict(url.query), follow=False, **extra)
response.redirect_chain = redirect_chain
if redirect_chain[-1] in redirect_chain[:-1]:
# Check that we're not redirecting to somewhere we've already
# been to, to prevent loops.
raise RedirectCycleError("Redirect loop detected.", last_response=response)
if len(redirect_chain) > 20:
# Such a lengthy chain likely also means a loop, but one with
# a growing path, changing view, or changing query argument;
# 20 is the value of "network.http.redirection-limit" from Firefox.
raise RedirectCycleError("Too many redirects.", last_response=response)
return response
示例8: get_link
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urljoin [as 别名]
def get_link(self, path, method, base_url):
fields = self.get_path_fields(path, method)
fields += self.get_serializer_fields(path, method)
fields += self.get_pagination_fields(path, method)
fields += self.get_filter_fields(path, method)
manual_fields = self.get_manual_fields(path, method)
fields = self.update_fields(fields, manual_fields)
if fields and any([field.location in ('form', 'body') for field in fields]):
encoding = self.get_encoding(path, method)
else:
encoding = None
description = self.get_description(path, method)
if base_url and path.startswith('/'):
path = path[1:]
return coreapi.Link(
url=urlparse.urljoin(base_url, path),
action=method.lower(),
encoding=encoding,
fields=fields,
description=description
)
示例9: get_images_url
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urljoin [as 别名]
def get_images_url(self):
return urljoin(self.url, self.IMAGE_LIST_URI)
示例10: get_image_manifest_url
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urljoin [as 别名]
def get_image_manifest_url(self, uuid):
return urljoin(self.url, self.IMAGE_URI % uuid)
示例11: url
# 需要导入模块: from django.utils.six.moves.urllib import parse [as 别名]
# 或者: from django.utils.six.moves.urllib.parse import urljoin [as 别名]
def url(self, name):
if self._base_url is None:
raise ValueError("This file is not accessible via a URL.")
return urlparse.urljoin(self._base_url, name).replace('\\', '/')