當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。