本文整理匯總了Python中django.conf.settings.STATIC_ROOT屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.STATIC_ROOT屬性的具體用法?Python settings.STATIC_ROOT怎麽用?Python settings.STATIC_ROOT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.STATIC_ROOT屬性的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def __init__(self, app_names=None, *args, **kwargs):
# List of locations with static files
self.locations = []
# Maps dir paths to an appropriate storage instance
self.storages = OrderedDict()
if not isinstance(settings.STATICFILES_DIRS, (list, tuple)):
raise ImproperlyConfigured(
"Your STATICFILES_DIRS setting is not a tuple or list; "
"perhaps you forgot a trailing comma?")
for root in settings.STATICFILES_DIRS:
if isinstance(root, (list, tuple)):
prefix, root = root
else:
prefix = ''
if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
raise ImproperlyConfigured(
"The STATICFILES_DIRS setting should "
"not contain the STATIC_ROOT setting")
if (prefix, root) not in self.locations:
self.locations.append((prefix, root))
for prefix, root in self.locations:
filesystem_storage = FileSystemStorage(location=root)
filesystem_storage.prefix = prefix
self.storages[root] = filesystem_storage
super(FileSystemFinder, self).__init__(*args, **kwargs)
示例2: check_settings
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def check_settings(base_url=None):
"""
Checks if the staticfiles settings have sane values.
"""
if base_url is None:
base_url = settings.STATIC_URL
if not base_url:
raise ImproperlyConfigured(
"You're using the staticfiles app "
"without having set the required STATIC_URL setting.")
if settings.MEDIA_URL == base_url:
raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
"settings must have different values")
if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and
(settings.MEDIA_ROOT == settings.STATIC_ROOT)):
raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
"settings must have different values")
示例3: check
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def check(self, **kwargs):
errors = []
if not isinstance(settings.STATICFILES_DIRS, (list, tuple)):
errors.append(Error(
'The STATICFILES_DIRS setting is not a tuple or list.',
hint='Perhaps you forgot a trailing comma?',
id='staticfiles.E001',
))
for root in settings.STATICFILES_DIRS:
if isinstance(root, (list, tuple)):
_, root = root
if settings.STATIC_ROOT and os.path.abspath(settings.STATIC_ROOT) == os.path.abspath(root):
errors.append(Error(
'The STATICFILES_DIRS setting should not contain the '
'STATIC_ROOT setting.',
id='staticfiles.E002',
))
return errors
示例4: check_settings
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def check_settings(base_url=None):
"""
Check if the staticfiles settings have sane values.
"""
if base_url is None:
base_url = settings.STATIC_URL
if not base_url:
raise ImproperlyConfigured(
"You're using the staticfiles app "
"without having set the required STATIC_URL setting.")
if settings.MEDIA_URL == base_url:
raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
"settings must have different values")
if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and
(settings.MEDIA_ROOT == settings.STATIC_ROOT)):
raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
"settings must have different values")
示例5: resource_file
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def resource_file(self, request, pk=None, version=None):
"""
get:
Gets the models `resource_file` contents
delete:
Disassociates the moodels `resource_file` contents
"""
try:
return handle_related_file(self.get_object(), 'resource_file', request, ['application/json'])
except Http404:
print("No resource_file set, returning default file as response")
with io.open(os.path.join(settings.STATIC_ROOT, 'model_resource.json')) as default_resource:
data = json.load(default_resource)
response = JsonResponse(data)
response['Content-Disposition'] = 'attachment; filename="{}"'.format('default_resource_file.json')
return response
示例6: relative_static_url
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def relative_static_url(self):
url = settings.STATIC_URL
rewrite_on = False
try:
if settings.REWRITE_STATIC_URLS is True:
rewrite_on = True
try:
multitenant_relative_url = settings.MULTITENANT_RELATIVE_STATIC_ROOT
except AttributeError:
# MULTITENANT_RELATIVE_STATIC_ROOT is an optional setting. Use the default of just appending
# the tenant schema_name to STATIC_ROOT if no configuration value is provided
multitenant_relative_url = "%s"
url = "/" + "/".join(s.strip("/") for s in [url, multitenant_relative_url]) + "/"
except AttributeError:
# REWRITE_STATIC_URLS not set - ignore
pass
return rewrite_on, url
示例7: getImage
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def getImage(self, url):
imagehash = hashlib.md5(url.encode('utf-8')).hexdigest()
if settings.STATIC_ROOT is None:
filepath = settings.STATICFILES_DIRS[0] + "webimg/" + imagehash + ".png"
else:
filepath = settings.STATIC_ROOT + "webimg/" + imagehash + ".png"
path = "static/webimg/" + imagehash + ".png"
options = {
'quiet': '',
'xvfb': '',
}
if not os.path.exists(filepath):
try:
imgkit.from_url(url, filepath, options=options)
except Exception as e:
logger.error(e)
return
return path
示例8: getSrc
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def getSrc(self, url):
imagehash = hashlib.md5(url.encode('utf-8')).hexdigest()
if settings.STATIC_ROOT is None:
filepath = settings.STATICFILES_DIRS[0] + "websrc/" + imagehash
else:
filepath = settings.STATIC_ROOT + "websrc/" + imagehash
if not os.path.exists(filepath):
ua = "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv 11.0) like Gecko"
headers = {
'User-Agent': ua
}
try:
res = requests.get(url, headers=headers, verify=False)
except Exception as e:
logger.error(e)
return
if "content-type" in res.headers:
if 'text/html' in res.headers['content-type']:
with open(filepath, 'w') as fp:
fp.write(res.text)
else:
with open(filepath, 'wb') as fp:
fp.write(res.content)
return imagehash
示例9: check_settings
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def check_settings(base_url=None):
"""
Checks if the staticfiles settings have sane values.
"""
if base_url is None:
base_url = settings.STATIC_URL
if not base_url:
raise ImproperlyConfigured(
"You're using the staticfiles app "
"without having set the required STATIC_URL setting.")
if settings.MEDIA_URL == base_url:
raise ImproperlyConfigured("The MEDIA_URL and STATIC_URL "
"settings must have different values")
if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and
(settings.MEDIA_ROOT == settings.STATIC_ROOT)):
raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
"settings must have different values")
示例10: fetch_resources
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def fetch_resources(uri, rel):
"""
Callback to allow xhtml2pdf/reportlab to retrieve Images,Stylesheets, etc.
`uri` is the href attribute from the html link element.
`rel` gives a relative path, but it's not used here.
"""
if settings.MEDIA_URL and uri.startswith(settings.MEDIA_URL):
path = os.path.join(settings.MEDIA_ROOT,
uri.replace(settings.MEDIA_URL, ""))
elif settings.STATIC_URL and uri.startswith(settings.STATIC_URL):
path = os.path.join(settings.STATIC_ROOT,
uri.replace(settings.STATIC_URL, ""))
if not os.path.exists(path):
for d in settings.STATICFILES_DIRS:
path = os.path.join(d, uri.replace(settings.STATIC_URL, ""))
if os.path.exists(path):
break
elif uri.startswith("http://") or uri.startswith("https://"):
path = uri
else:
raise UnsupportedMediaPathException('media urls must start with %s or %s' % (
settings.MEDIA_URL, settings.STATIC_URL))
return path
示例11: upgrade
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def upgrade(pargs):
environ['DJANGO_SETTINGS_MODULE'] = 'teamvault.settings'
environ.setdefault("TEAMVAULT_CONFIG_FILE", "/etc/teamvault.cfg")
print("\n### Running migrations...\n")
execute_from_command_line(["", "migrate", "--noinput", "-v", "3", "--traceback"])
print("\n### Gathering static files...\n")
from django.conf import settings
try:
rmtree(settings.STATIC_ROOT)
except FileNotFoundError:
pass
mkdir(settings.STATIC_ROOT)
execute_from_command_line(["", "collectstatic", "--noinput"])
print("\n### Updating search index...\n")
execute_from_command_line(["", "update_search_index"])
示例12: link_callback
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def link_callback(uri, rel):
# convert URIs to absolute system paths
if uri.startswith(settings.MEDIA_URL):
path = os.path.join(settings.MEDIA_ROOT,
uri.replace(settings.MEDIA_URL, ""))
elif uri.startswith(settings.STATIC_URL):
path = os.path.join(settings.STATIC_ROOT,
uri.replace(settings.STATIC_URL, ""))
else:
# handle absolute uri (i.e., "http://my.tld/a.png")
return uri
# make sure that the local file exists
if not os.path.isfile(path):
raise Exception(
"Media URI must start with "
f"'{settings.MEDIA_URL}' or '{settings.STATIC_URL}'")
return path
示例13: _get_apk_link
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import STATIC_ROOT [as 別名]
def _get_apk_link(cls) -> str:
local_apk = os.path.join(settings.STATIC_ROOT, "apk/shareberry.apk")
if os.path.isfile(local_apk):
return os.path.join(settings.STATIC_URL, "apk/shareberry.apk")
return "https://github.com/raveberry/shareberry/raw/master/app/release/shareberry.apk"