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
| Attribute | Type | Description |
|---|---|---|
| application | WSGI application | The underlying WSGI application that this middleware wraps and delegates requests to when they do not match the file handling criteria. |
| base_url | ParseResult | A 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
| Name | Type | Description |
|---|---|---|
| application | WSGI application | The 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
| Name | Type | Description |
|---|---|---|
| url | string | The full request URL to be converted into a local filesystem path |
Returns
| Type | Description |
|---|---|
string | The 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
| Name | Type | Description |
|---|---|---|
| request | [HttpRequest](../../http/request/httprequest.md?sid=django_http_request_httprequest) | The incoming Django request object containing the path to be checked |
Returns
| Type | Description |
|---|---|
[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
| Name | Type | Description |
|---|---|---|
| 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
| Type | Description |
|---|---|
[FileResponse](../../http/response/fileresponse.md?sid=django_http_response_fileresponse) | The streaming response containing the requested file's data |