本文整理汇总了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)
示例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)
示例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)
示例4: getfile
# 需要导入模块: from django.contrib.staticfiles import views [as 别名]
# 或者: from django.contrib.staticfiles.views import serve [as 别名]
def getfile(request):
return serve(request, 'File')
示例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)
示例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)
示例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
示例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)
示例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)
示例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
示例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