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


Python settings.MEDIA_URL属性代码示例

本文整理汇总了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") 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:18,代码来源:static.py

示例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") 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:20,代码来源:utils.py

示例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
        ) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:21,代码来源:storage.py

示例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") 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:19,代码来源:utils.py

示例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 
开发者ID:SubstraFoundation,项目名称:substra-backend,代码行数:23,代码来源:sql_printing_middleware.py

示例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_ 
开发者ID:wuyue92tree,项目名称:django-adminlte-ui,代码行数:23,代码来源:adminlte_options.py

示例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),
    ) 
开发者ID:blackye,项目名称:luscan-devel,代码行数:22,代码来源:static.py

示例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,
        }
    ) 
开发者ID:stxnext-csr,项目名称:volontulo,代码行数:22,代码来源:__init__.py

示例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) 
开发者ID:stxnext-csr,项目名称:volontulo,代码行数:27,代码来源:offers.py

示例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") 
开发者ID:drexly,项目名称:openhgsenti,代码行数:19,代码来源:utils.py

示例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,
    } 
开发者ID:mozilla,项目名称:foundation.mozilla.org,代码行数:19,代码来源:homepage_tags.py

示例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') 
开发者ID:SableWalnut,项目名称:wagtailinvoices,代码行数:39,代码来源:editor.py

示例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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:12,代码来源:widgets.py

示例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} 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:8,代码来源:context_processors.py

示例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) 
开发者ID:Tenma-Server,项目名称:Tenma,代码行数:10,代码来源:simple_crop.py


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