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