當前位置: 首頁>>代碼示例>>Python>>正文


Python static.static方法代碼示例

本文整理匯總了Python中django.conf.urls.static.static方法的典型用法代碼示例。如果您正苦於以下問題:Python static.static方法的具體用法?Python static.static怎麽用?Python static.static使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.conf.urls.static的用法示例。


在下文中一共展示了static.static方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: static

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [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

示例2: staticfiles_urlpatterns

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [as 別名]
def staticfiles_urlpatterns(prefix=None):
    """
    Helper function to return a URL pattern for serving static files.
    """
    if prefix is None:
        prefix = settings.STATIC_URL
    return static(prefix, view=serve)

# Only append if urlpatterns are empty 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:11,代碼來源:urls.py

示例3: staticfiles_urlpatterns

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [as 別名]
def staticfiles_urlpatterns(prefix=None):
    """
    Helper function to return a URL pattern for serving static files.
    """
    if prefix is None:
        prefix = settings.STATIC_URL
    return static(prefix, view=serve)


# Only append if urlpatterns are empty 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:12,代碼來源:urls.py

示例4: get_current_urls

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [as 別名]
def get_current_urls():
    urls = BaseRouter.get_instance().urls + [
        url(r'^auth/', include(auth_patterns)),
        url(r'^auth/registration/', include(auth_registration_patterns)),
        url(r'^docs/', include('rest_framework_swagger.urls')),
    ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    if settings.DEBUG:
        import debug_toolbar
        urls.append(url(r'^__debug__/', include(debug_toolbar.urls)))
    return urls 
開發者ID:OpenAgricultureFoundation,項目名稱:gro-api,代碼行數:12,代碼來源:urls.py

示例5: test_serve

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [as 別名]
def test_serve(self):
        "The static view can serve static media"
        media_files = ['file.txt', 'file.txt.gz', '%2F.txt']
        for filename in media_files:
            response = self.client.get('/%s/%s' % (self.prefix, quote(filename)))
            response_content = b''.join(response)
            file_path = path.join(media_dir, filename)
            with open(file_path, 'rb') as fp:
                self.assertEqual(fp.read(), response_content)
            self.assertEqual(len(response_content), int(response['Content-Length']))
            self.assertEqual(mimetypes.guess_type(file_path)[1], response.get('Content-Encoding', None)) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:13,代碼來源:test_static.py

示例6: test_chunked

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [as 別名]
def test_chunked(self):
        "The static view should stream files in chunks to avoid large memory usage"
        response = self.client.get('/%s/%s' % (self.prefix, 'long-line.txt'))
        first_chunk = next(response.streaming_content)
        self.assertEqual(len(first_chunk), FileResponse.block_size)
        second_chunk = next(response.streaming_content)
        response.close()
        # strip() to prevent OS line endings from causing differences
        self.assertEqual(len(second_chunk.strip()), 1449) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:11,代碼來源:test_static.py

示例7: setUp

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [as 別名]
def setUp(self):
        super().setUp()
        self._old_views_urlpatterns = urls.urlpatterns[:]
        urls.urlpatterns += static('/media/', document_root=media_dir) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:test_static.py

示例8: test_prefix

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [as 別名]
def test_prefix(self):
        self.assertEqual(static('test')[0].pattern.regex.pattern, '^test(?P<path>.*)$') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:test_static.py

示例9: test_debug_off

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [as 別名]
def test_debug_off(self):
        """No URLs are served if DEBUG=False."""
        self.assertEqual(static('test'), []) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:5,代碼來源:test_static.py

示例10: test_special_prefix

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [as 別名]
def test_special_prefix(self):
        """No URLs are served if prefix contains '://'."""
        self.assertEqual(static('http://'), []) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:5,代碼來源:test_static.py

示例11: test_empty_prefix

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [as 別名]
def test_empty_prefix(self):
        with self.assertRaisesMessage(ImproperlyConfigured, 'Empty static prefix not permitted'):
            static('') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:5,代碼來源:test_static.py

示例12: test_special_prefix

# 需要導入模塊: from django.conf.urls import static [as 別名]
# 或者: from django.conf.urls.static import static [as 別名]
def test_special_prefix(self):
        """No URLs are served if prefix contains a netloc part."""
        self.assertEqual(static('http://example.org'), [])
        self.assertEqual(static('//example.org'), []) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:test_static.py


注:本文中的django.conf.urls.static.static方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。