Skip to main content

FSFilesHandler

WSGI middleware that intercepts calls to a directory, as defined by one of the *_ROOT settings, and serves those files, publishing them under *_URL.

Attributes

AttributeTypeDescription
applicationWSGI applicationThe underlying WSGI application that this middleware wraps and delegates requests to when they do not match the file handling criteria.
base_urlParseResultA parsed URL object representing the base path under which files are served, used to determine if an incoming request should be intercepted.

Constructor

Signature

def FSFilesHandler(
application: WSGI application
)

Parameters

NameTypeDescription
applicationWSGI applicationThe WSGI application object to be wrapped by the middleware.

Methods


file_path()

@classmethod
def file_path(
url: string
) - > string

Return the relative path to the file on disk for the given URL.

Parameters

NameTypeDescription
urlstringThe full request URL to be converted into a local filesystem path

Returns

TypeDescription
stringThe OS-specific relative file path derived from the URL after stripping the base URL prefix

get_response()

@classmethod
def get_response(
request: [HttpRequest](../../http/request/httprequest.md?sid=django_http_request_httprequest)
) - > [HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)

Intercepts the request to serve a static file if the path matches; otherwise, delegates to the parent handler.

Parameters

NameTypeDescription
request[HttpRequest](../../http/request/httprequest.md?sid=django_http_request_httprequest)The incoming Django request object containing the path to be checked

Returns

TypeDescription
[HttpResponse](../../http/response/httpresponse.md?sid=django_http_response_httpresponse)An HTTP response containing the file content or the result of the next handler in the chain

serve()

@classmethod
def serve(
request: [HttpRequest](../../http/request/httprequest.md?sid=django_http_request_httprequest)
) - > [FileResponse](../../http/response/fileresponse.md?sid=django_http_response_fileresponse)

Processes the request to locate and return a file from the local filesystem using the configured document root.

Parameters

NameTypeDescription
request[HttpRequest](../../http/request/httprequest.md?sid=django_http_request_httprequest)The request object used to determine which file to serve from the disk

Returns

TypeDescription
[FileResponse](../../http/response/fileresponse.md?sid=django_http_response_fileresponse)The streaming response containing the requested file's data