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


Python settings.STATICFILES_DIRS属性代码示例

本文整理汇总了Python中django.conf.settings.STATICFILES_DIRS属性的典型用法代码示例。如果您正苦于以下问题:Python settings.STATICFILES_DIRS属性的具体用法?Python settings.STATICFILES_DIRS怎么用?Python settings.STATICFILES_DIRS使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.conf.settings的用法示例。


在下文中一共展示了settings.STATICFILES_DIRS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [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) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:finders.py

示例2: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [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()
        for root in settings.STATICFILES_DIRS:
            if isinstance(root, (list, tuple)):
                prefix, root = root
            else:
                prefix = ''
            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().__init__(*args, **kwargs) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:19,代码来源:finders.py

示例3: check

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [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 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:20,代码来源:finders.py

示例4: getImage

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [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 
开发者ID:nict-csl,项目名称:exist,代码行数:20,代码来源:views.py

示例5: getSrc

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [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 
开发者ID:nict-csl,项目名称:exist,代码行数:27,代码来源:views.py

示例6: test_upload_second_photo

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [as 别名]
def test_upload_second_photo(self):
        # pre register pet
        pet = self.create_pet()

        # login
        self.login()

        # go to own pet
        self.browser.get(self.live_server_url + "/pets/{}/".format(pet.slug))

        # upload some new photo
        img_path = os.path.abspath("{}/img/{}.png".format(settings.STATICFILES_DIRS[0], "logo"))
        profile_picture = self.browser.find_element_by_name("another_picture")
        profile_picture.send_keys(img_path)

        img_before = len(self.browser.find_elements_by_tag_name("img"))

        submit = self.browser.find_element_by_name("submit")
        submit.click()

        img_after = len(self.browser.find_elements_by_tag_name("img"))

        # verify new photo is showing
        self.assertIn("More photos", self.browser.page_source)
        self.assertEquals(img_after, img_before + 1) 
开发者ID:jllorencetti,项目名称:pets,代码行数:27,代码来源:tests.py

示例7: fetch_resources

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [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 
开发者ID:silverapp,项目名称:silver,代码行数:26,代码来源:pdf.py

示例8: load_custom_css

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [as 别名]
def load_custom_css(var):
    if var.startswith('/'):
        var = var.lstrip('/')

    is_file = os.path.isfile(os.path.join(settings.STATIC_ROOT, var))

    if is_file:
        return '<link href="' + os.path.join('/static', var) + '" rel="stylesheet" />'

    else:
        for path in settings.STATICFILES_DIRS:
            is_file = os.path.isfile(os.path.join(path, var))
            if is_file:
                return '<link href="' + os.path.join('/static', var) + '" rel="stylesheet" />'

    return '<style>' + var + '</style>' 
开发者ID:tethysplatform,项目名称:tethys,代码行数:18,代码来源:site_settings.py

示例9: find

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [as 别名]
def find(self, path, all=False):
        """
        Looks for files in the extra locations
        as defined in ``STATICFILES_DIRS``.
        """
        matches = []
        for prefix, root in self.locations:
            if root not in searched_locations:
                searched_locations.append(root)
            matched_path = self.find_location(root, path, prefix)
            if matched_path:
                if not all:
                    return matched_path
                matches.append(matched_path)
        return matches 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:17,代码来源:finders.py

示例10: find

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [as 别名]
def find(self, path, all=False):
        """
        Look for files in the extra locations as defined in STATICFILES_DIRS.
        """
        matches = []
        for prefix, root in self.locations:
            if root not in searched_locations:
                searched_locations.append(root)
            matched_path = self.find_location(root, path, prefix)
            if matched_path:
                if not all:
                    return matched_path
                matches.append(matched_path)
        return matches 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:16,代码来源:finders.py

示例11: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [as 别名]
def __init__(self, app_names=None, *args, **kwargs):
        # Don't call parent's init method as settings.STATICFILES_DIRS will be loaded
        # by the standard FileSystemFinder already.

        # Instead of initializing the locations and storages now, we'll do so lazily
        # the first time they are needed.
        self._locations = {}
        self._storages = {} 
开发者ID:django-tenants,项目名称:django-tenants,代码行数:10,代码来源:finders.py

示例12: get_context_data

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [as 别名]
def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        if not re.compile(r'\w{32}').match(self.kwargs['pk']):
            return context
        if settings.STATIC_ROOT is None:
            srcpath = settings.STATICFILES_DIRS[0] + 'websrc/' + self.kwargs['pk']
        else:
            srcpath = settings.STATIC_ROOT + 'websrc/' + self.kwargs['pk']
        f = open(srcpath, 'r')
        context['websrc'] = f.read()
        f.close()
        return context 
开发者ID:nict-csl,项目名称:exist,代码行数:14,代码来源:views.py

示例13: getContents

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [as 别名]
def getContents(request, pk):
    if not re.compile(r'(?=(\b[a-fA-F0-9]{32}\b))').match(pk):
        return redirect('index')
    if settings.STATIC_ROOT is None:
        filepath = settings.STATICFILES_DIRS[0] + 'websrc/' + pk
    else:
        filepath = settings.STATIC_ROOT + 'websrc/' + pk
    f = open(filepath, 'rb')
    contents = f.read()
    f.close()
    response = HttpResponse(contents)
    response["Content-Disposition"] = "filename=%s" % pk
    return response 
开发者ID:nict-csl,项目名称:exist,代码行数:15,代码来源:views.py

示例14: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [as 别名]
def __init__ (self, blast_path='blastp',
        blastdb=os.sep.join([settings.STATICFILES_DIRS[0], 'blast', 'protwis_blastdb']), top_results=1):

        self.blast_path = blast_path
        self.blastdb = blastdb
        #typicaly top scored result is enough, but for sequences with missing
        #residues it is better to use more results to avoid getting sequence of
        #e.g.  different species
        self.top_results = top_results

    #takes Bio.Seq sequence as an input and returns a list of tuples with the
    #alignments 
开发者ID:protwis,项目名称:protwis,代码行数:14,代码来源:functions.py

示例15: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import STATICFILES_DIRS [as 别名]
def __init__ (self, pdb_file=None, pdb_filename=None, structure=None, pdb_code=None, blast_path='blastp',
        blastdb=os.sep.join([settings.STATICFILES_DIRS[0], 'blast', 'protwis_blastdb']),top_results=1, sequence_parser=False, signprot=False):
    
        # pdb_file can be either a name/path or a handle to an open file
        self.pdb_file = pdb_file
        self.pdb_filename = pdb_filename

        # if pdb 4 letter code is specified
        self.pdb_code = pdb_code
        
        # dictionary of 'MappedResidue' object storing information about alignments and bw numbers
        self.residues = {}
        self.pdb_seq = {} #Seq('')
        # list of uniprot ids returned from blast
        self.prot_id_list = []
        #setup for local blast search
        self.blast = BlastSearch(blast_path=blast_path, blastdb=blastdb,top_results=top_results)
        
        # calling sequence parser
        if sequence_parser:
            if pdb_code:
                struct = Structure.objects.get(pdb_code__index=self.pdb_code)
            if not signprot:
                if pdb_code:
                    s = SequenceParser(pdb_file=self.pdb_file, wt_protein_id=struct.protein_conformation.protein.parent.id)
                else:
                    s = SequenceParser(pdb_file=self.pdb_file)#, wt_protein_id=struct.protein_conformation.protein.parent.id)
            else:
                s = SequenceParser(pdb_file=self.pdb_file, wt_protein_id=signprot.id)
            self.pdb_structure = s.pdb_struct
            self.mapping = s.mapping
            self.wt = s.wt
        else:
            if self.pdb_file:
                self.pdb_structure = PDBParser(PERMISSIVE=True, QUIET=True).get_structure('ref', self.pdb_file)[0]
            elif self.pdb_filename:
                self.pdb_structure = PDBParser(PERMISSIVE=True, QUIET=True).get_structure('ref', self.pdb_filename)[0]
            else:
                self.pdb_structure = structure

            self.parse_structure(self.pdb_structure) 
开发者ID:protwis,项目名称:protwis,代码行数:43,代码来源:assign_generic_numbers_gpcr.py


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