### Prepare Project for Example Usage Source: https://github.com/rexzhang/asgi-middleware-static-file/blob/main/README.md Clone the repository and navigate to the example directory to set up the project for testing. ```shell pip3 install -U ASGIMiddlewareStaticFile git clone https://github.com/rexzhang/asgi-middleware-static-file.git cd asgi-middleware-static-file/example ``` -------------------------------- ### Install ASGIMiddlewareStaticFile Source: https://github.com/rexzhang/asgi-middleware-static-file/blob/main/README.md Install the package using pip. This command ensures you have the latest version of the middleware. ```shell pip3 install -U ASGIMiddlewareStaticFile ``` -------------------------------- ### Start Pure ASGI Server Source: https://github.com/rexzhang/asgi-middleware-static-file/blob/main/README.md Run the pure ASGI application using uvicorn. Ensure you are in the correct directory. ```shell (venv) ➜ example git:(main) ✗ uvicorn example_pure_asgi:app ``` -------------------------------- ### Start Quart Server Source: https://github.com/rexzhang/asgi-middleware-static-file/blob/main/README.md Run the Quart application using uvicorn. This is suitable for Flask-like applications. ```shell (venv) ➜ example git:(main) ✗ uvicorn example_quart:app ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/rexzhang/asgi-middleware-static-file/blob/main/README.md Install the package in editable mode along with development dependencies. ```shell pip install -U -e ".[dev]" ``` -------------------------------- ### Start Django Server Source: https://github.com/rexzhang/asgi-middleware-static-file/blob/main/README.md Launch the Django application using uvicorn. This command assumes static files have been collected. ```shell (venv) ➜ example_django git:(main) ✗ uvicorn example_django.asgi:application ``` -------------------------------- ### Start WSGI App Server Source: https://github.com/rexzhang/asgi-middleware-static-file/blob/main/README.md Serve a WSGI application, such as Flask or Django in WSGI mode, using uvicorn. ```shell (venv) ➜ example git:(main) ✗ uvicorn example_wsgi_app:app ``` -------------------------------- ### Configure Multiple Static File Directories Source: https://github.com/rexzhang/asgi-middleware-static-file/blob/main/README.md Provide a list of paths to `static_root_paths` to serve static files from multiple directories. ```python static_root_paths = [ "/path/a", "path/b" ] application = ASGIMiddlewareStaticFile( application, static_url=settings.STATIC_URL, static_root_paths=static_root_paths, ) ``` -------------------------------- ### Test Static File Serving with wget Source: https://github.com/rexzhang/asgi-middleware-static-file/blob/main/README.md Use wget to test if the static file is being served correctly from the local server. ```shell (venv) ➜ example git:(main) ✗ wget http://127.0.0.1:8000/static/DEMO --2022-02-10 16:02:07-- http://127.0.0.1:8000/static/DEMO 正在连接 127.0.0.1:8000... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:26 [] 正在保存至: “DEMO” DEMO 100%[===========================================================================>] 26 --.-KB/s 用时 0s 2022-02-10 16:02:08 (529 KB/s) - 已保存 “DEMO” [26/26]) ``` -------------------------------- ### Collect Static Files for Django Project Source: https://github.com/rexzhang/asgi-middleware-static-file/blob/main/README.md Execute the Django management command to collect all static files into the designated directory. ```shell (venv) ➜ example git:(main) cd example_django (venv) ➜ example_django git:(main) ✗ python manage.py collectstatic 129 static files copied to '/Users/rex/p/asgi-middleware-static-file/example/example_django/staticfiles'. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.