本文整理匯總了Python中django.conf.settings.MEDIA_URL屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.MEDIA_URL屬性的具體用法?Python settings.MEDIA_URL怎麽用?Python settings.MEDIA_URL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類django.conf.settings
的用法示例。
在下文中一共展示了settings.MEDIA_URL屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_media_prefix
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [as 別名]
def get_media_prefix(parser, token):
"""
Populates a template variable with the media prefix,
``settings.MEDIA_URL``.
Usage::
{% get_media_prefix [as varname] %}
Examples::
{% get_media_prefix %}
{% get_media_prefix as media_prefix %}
"""
return PrefixNode.handle_token(parser, token, "MEDIA_URL")
示例2: check_settings
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [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: __init__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [as 別名]
def __init__(self, location=None, base_url=None, file_permissions_mode=None,
directory_permissions_mode=None):
if location is None:
location = settings.MEDIA_ROOT
self.base_location = location
self.location = abspathu(self.base_location)
if base_url is None:
base_url = settings.MEDIA_URL
elif not base_url.endswith('/'):
base_url += '/'
self.base_url = base_url
self.file_permissions_mode = (
file_permissions_mode if file_permissions_mode is not None
else settings.FILE_UPLOAD_PERMISSIONS
)
self.directory_permissions_mode = (
directory_permissions_mode if directory_permissions_mode is not None
else settings.FILE_UPLOAD_DIRECTORY_PERMISSIONS
)
示例4: check_settings
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [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: __call__
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [as 別名]
def __call__(self, request):
response = self.get_response(request)
if (len(connection.queries) == 0 or
request.path_info.startswith('/favicon.ico') or
request.path_info.startswith(settings.STATIC_URL) or
request.path_info.startswith(settings.MEDIA_URL)):
return response
indentation = 2
print(("\n\n%s\033[1;35m[SQL Queries for]\033[1;34m %s\033[0m\n" % (" " * indentation, request.path_info)))
total_time = 0.0
for query in connection.queries:
if query['sql']:
nice_sql = query['sql'].replace('"', '').replace(',', ', ')
sql = "\033[1;31m[%s]\033[0m %s" % (query['time'], nice_sql)
total_time = total_time + float(query['time'])
print(("%s%s\n" % (" " * indentation, sql)))
replace_tuple = (" " * indentation, str(total_time), str(len(connection.queries)))
print(("%s\033[1;32m[TOTAL TIME: %s seconds (%s queries)]\033[0m" % replace_tuple))
return response
示例6: get_adminlte_option
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [as 別名]
def get_adminlte_option(option_name, request=None):
config_ = {}
config_list = Options.objects.filter(valid=True)
if config_list.filter(option_name=option_name):
config_[option_name] = config_list.get(
option_name=option_name).option_value
if request and option_name == 'avatar_field':
try:
# request.user.head_avatar
image_path = eval(config_[option_name]).name
if image_path:
config_[option_name] = settings.MEDIA_URL + image_path
else:
config_[option_name] = None
except Exception as e:
traceback.print_exc()
config_[option_name] = None
config_['valid'] = config_list.get(
option_name=option_name).valid
return config_
示例7: static
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [as 別名]
def static(prefix, view='django.views.static.serve', **kwargs):
"""
Helper function to return a URL pattern for serving files in debug mode.
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = patterns('',
# ... the rest of your URLconf goes here ...
) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
"""
# No-op if not in debug mode or an non-local prefix
if not settings.DEBUG or (prefix and '://' in prefix):
return []
elif not prefix:
raise ImproperlyConfigured("Empty static prefix not permitted")
return patterns('',
url(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, kwargs=kwargs),
)
示例8: homepage
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [as 別名]
def homepage(request):
u"""Main view of app.
We will display page with few step CTA links?
:param request: WSGIRequest instance
"""
if logged_as_admin(request):
offers = Offer.objects.get_for_administrator()
else:
offers = Offer.objects.get_weightened()
return render(
request,
"homepage.html",
{
'offers': offers,
'MEDIA_URL': settings.MEDIA_URL,
}
)
示例9: get
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [as 別名]
def get(request, slug, id_):
u"""View responsible for showing details of particular offer."""
offer = get_object_or_404(Offer, id=id_)
try:
main_image = OfferImage.objects.get(offer=offer, is_main=True)
except OfferImage.DoesNotExist:
main_image = ''
volunteers = None
users = [u.user.id for u in offer.organization.userprofiles.all()]
if (
request.user.is_authenticated() and (
request.user.userprofile.is_administrator or
request.user.userprofile.id in users
)
):
volunteers = offer.volunteers.all()
context = {
'offer': offer,
'volunteers': volunteers,
'MEDIA_URL': settings.MEDIA_URL,
'main_image': main_image,
}
return render(request, "offers/show_offer.html", context=context)
示例10: check_settings
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [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")
示例11: homepage_image_with_class
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [as 別名]
def homepage_image_with_class(context, path, classname):
root = settings.MEDIA_URL
if settings.USE_S3:
awsl = settings.AWS_LOCATION
awscd = settings.AWS_S3_CUSTOM_DOMAIN
if awscd in root and awsl not in root:
old = awscd
new = awscd + '/' + awsl
root = root.replace(old, new)
url = '{}{}'.format(root, path)
return {
'url': url,
'classname': classname,
}
示例12: serve_pdf
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [as 別名]
def serve_pdf(invoice, request):
# Convert HTML URIs to absolute system paths so xhtml2pdf can access those resources
def link_callback(uri, rel):
# use short variable names
sUrl = settings.STATIC_URL # Typically /static/
sRoot = settings.STATIC_ROOT # Typically /home/userX/project_static/
mUrl = settings.MEDIA_URL # Typically /static/media/
mRoot = settings.MEDIA_ROOT # Typically /home/userX/project_static/media/
# convert URIs to absolute system paths
if uri.startswith(mUrl):
path = os.path.join(mRoot, uri.replace(mUrl, ""))
elif uri.startswith(sUrl):
path = os.path.join(sRoot, uri.replace(sUrl, ""))
# make sure that file exists
if not os.path.isfile(path):
raise Exception(
'media URI must start with %s or %s' % \
(sUrl, mUrl))
return path
# Render html content through html template with context
template = get_template(settings.PDF_TEMPLATE)
html = template.render(Context(invoice))
# Write PDF to file
# file = open(os.path.join(settings.MEDIA_ROOT, 'Invoice #' + str(id) + '.pdf'), "w+b")
file = StringIO.StringIO()
pisaStatus = pisa.CreatePDF(html, dest=file, link_callback=link_callback)
# Return PDF document through a Django HTTP response
file.seek(0)
# pdf = file.read()
# file.close() # Don't forget to close the file handle
return HttpResponse(file, content_type='application/pdf')
示例13: absolute_path
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [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)
示例14: media
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [as 別名]
def media(request):
"""
Adds media-related context variables to the context.
"""
return {'MEDIA_URL': settings.MEDIA_URL}
示例15: _create_cache_paths
# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import MEDIA_URL [as 別名]
def _create_cache_paths(filepath, width, height):
filename = filepath.split('/')[-1]
extension = os.path.splitext(filename)[1].lower() if os.path.splitext(filename)[1] else '.jpg'
cache = 'CACHE/' + filename.split('.')[0] + '-' + str(width) + 'x' + str(height) + extension
cache_static = settings.MEDIA_ROOT + '/' + cache
cache_url = settings.MEDIA_URL + cache
return (cache_static, cache_url)