本文整理汇总了Python中django.utils.six.moves.urllib.request.url2pathname方法的典型用法代码示例。如果您正苦于以下问题:Python request.url2pathname方法的具体用法?Python request.url2pathname怎么用?Python request.url2pathname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.utils.six.moves.urllib.request
的用法示例。
在下文中一共展示了request.url2pathname方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: file_path
# 需要导入模块: from django.utils.six.moves.urllib import request [as 别名]
# 或者: from django.utils.six.moves.urllib.request import url2pathname [as 别名]
def file_path(self, url):
"""
Returns the relative path to the media file on disk for the given URL.
"""
relative_url = url[len(self.base_url[2]):]
return url2pathname(relative_url)
示例2: file_path
# 需要导入模块: from django.utils.six.moves.urllib import request [as 别名]
# 或者: from django.utils.six.moves.urllib.request import url2pathname [as 别名]
def file_path(self, url):
"""
Returns the relative path to the file on disk for the given URL.
"""
relative_url = url[len(self.base_url[2]):]
return url2pathname(relative_url)
示例3: get_filename
# 需要导入模块: from django.utils.six.moves.urllib import request [as 别名]
# 或者: from django.utils.six.moves.urllib.request import url2pathname [as 别名]
def get_filename(self, basename):
"""
Returns full path to a file, for example:
get_filename('css/one.css') -> '/full/path/to/static/css/one.css'
"""
filename = None
# First try finding the file using the storage class.
# This is skipped in DEBUG mode as files might be outdated in
# compressor's final destination (COMPRESS_ROOT) during development
if not settings.DEBUG:
try:
# call path first so remote storages don't make it to exists,
# which would cause network I/O
filename = self.storage.path(basename)
if not self.storage.exists(basename):
filename = None
except NotImplementedError:
# remote storages don't implement path, access the file locally
if compressor_file_storage.exists(basename):
filename = compressor_file_storage.path(basename)
# secondly try to find it with staticfiles
if not filename and self.finders:
filename = self.finders.find(url2pathname(basename))
if filename:
return filename
# or just raise an exception as the last resort
raise UncompressableFileError(
"'%s' could not be found in the COMPRESS_ROOT '%s'%s" %
(basename, settings.COMPRESS_ROOT,
self.finders and " or with staticfiles." or "."))