当前位置: 首页>>代码示例>>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;未经允许,请勿转载。