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


Python views.serve方法代码示例

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


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

示例1: serve

# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [as 别名]
def serve(request, path, insecure=False, **kwargs):
    """
    Serve static files below a given point in the directory structure or
    from locations inferred from the staticfiles finders.

    To use, put a URL pattern such as::

        from django.contrib.staticfiles import views

        url(r'^(?P<path>.*)$', views.serve)

    in your URLconf.

    It uses the django.views.static.serve() view to serve the found files.
    """
    if not settings.DEBUG and not insecure:
        raise Http404
    normalized_path = posixpath.normpath(unquote(path)).lstrip('/')
    absolute_path = finders.find(normalized_path)
    if not absolute_path:
        if path.endswith('/') or path == '':
            raise Http404("Directory indexes are not allowed here.")
        raise Http404("'%s' could not be found" % path)
    document_root, path = os.path.split(absolute_path)
    return static.serve(request, path, document_root=document_root, **kwargs) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:27,代码来源:views.py

示例2: serve

# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [as 别名]
def serve(request, path, insecure=False, **kwargs):
    """
    Serve static files below a given point in the directory structure or
    from locations inferred from the staticfiles finders.

    To use, put a URL pattern such as::

        from django.contrib.staticfiles import views

        url(r'^(?P<path>.*)$', views.serve)

    in your URLconf.

    It uses the django.views.static.serve() view to serve the found files.
    """
    if not settings.DEBUG and not insecure:
        raise Http404
    normalized_path = posixpath.normpath(path).lstrip('/')
    absolute_path = finders.find(normalized_path)
    if not absolute_path:
        if path.endswith('/') or path == '':
            raise Http404("Directory indexes are not allowed here.")
        raise Http404("'%s' could not be found" % path)
    document_root, path = os.path.split(absolute_path)
    return static.serve(request, path, document_root=document_root, **kwargs) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:27,代码来源:views.py

示例3: get_response

# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [as 别名]
def get_response(self, request):
        from django.http import Http404

        if self._should_handle(request.path):
            try:
                return self.serve(request)
            except Http404 as e:
                return response_for_exception(request, e)
        return super().get_response(request) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:11,代码来源:handlers.py

示例4: getfile

# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [as 别名]
def getfile(request):
   return serve(request, 'File') 
开发者ID:smahesh29,项目名称:Django-WebApp,代码行数:4,代码来源:views.py

示例5: serve

# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [as 别名]
def serve(self, request):
        """
        Actually serves the request path.
        """
        return serve(request, self.file_path(request.path), insecure=True) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:7,代码来源:handlers.py

示例6: get_response

# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [as 别名]
def get_response(self, request):
        from django.http import Http404

        if self._should_handle(request.path):
            try:
                return self.serve(request)
            except Http404 as e:
                if settings.DEBUG:
                    from django.views import debug
                    return debug.technical_404_response(request, e)
        return super(StaticFilesHandler, self).get_response(request) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:handlers.py

示例7: staticfiles_urlpatterns

# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [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

示例8: serve

# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [as 别名]
def serve(self, request):
        """Serve the request path."""
        return serve(request, self.file_path(request.path), insecure=True) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:5,代码来源:handlers.py

示例9: get_response

# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [as 别名]
def get_response(self, request):
        from django.http import Http404

        if self._should_handle(request.path):
            try:
                return self.serve(request)
            except Http404 as e:
                if settings.DEBUG:
                    from django.views import debug
                    return debug.technical_404_response(request, e)
        return super().get_response(request) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:13,代码来源:handlers.py

示例10: staticfiles_urlpatterns

# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [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

示例11: serve_static

# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [as 别名]
def serve_static(request: HttpRequest, path: str) -> HttpResponse:
        response = staticfiles_serve(request, path)
        response["Access-Control-Allow-Origin"] = "*"
        return response 
开发者ID:zulip,项目名称:zulip,代码行数:6,代码来源:dev_urls.py


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