"""Views and functions for serving static files. These are only to be used duringdevelopment, and SHOULD NOT be used in a production setting."""importosimportposixpathfromdjango.confimportsettingsfromdjango.contrib.staticfilesimportfindersfromdjango.httpimportHttp404fromdjango.viewsimportstaticdefserve(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 path('<path:path>', views.serve) in your URLconf. It uses the django.views.static.serve() view to serve the found files. """ifnotsettings.DEBUGandnotinsecure:raiseHttp404normalized_path=posixpath.normpath(path).lstrip("/")absolute_path=finders.find(normalized_path)ifnotabsolute_path:ifpath.endswith("/")orpath=="":raiseHttp404("Directory indexes are not allowed here.")raiseHttp404("'%s' could not be found"%path)document_root,path=os.path.split(absolute_path)returnstatic.serve(request,path,document_root=document_root,**kwargs)