Multiple directories in StaticFiles
See original GitHub issueThe feature request is to be able to serve different directories under the same route.
The StaticFiles
app only allows serving from one directory, so we can’t have have multiple apps under the same route.
Suggestions :
1- Add an add_directory
method to StaticFiles
app, to allow adding multiple directories to the the same StaticFiles
app and it can be used like so :
static_app = StaticFiles(directory="static")
static_app.add_directory("another_static_dir")
We can also add add_directories
which accepts a list of directories
- I’ve made a PR for the
add_directory
#626
2- Allow passing a list of directories in init
, I know it’s not a good idea to change the api 😕, and to avoid that one way could be adding a kwarg directories: List[str]
, I’m also aware it’s not a good idea :3 (even worse) to expose two ways of doing things directory
and directories
but the way of implementing it should be discussed, ofc if accepted.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (6 by maintainers)
Top GitHub Comments
fyi, I used the following solution :
Closing with the same rationale as https://github.com/encode/starlette/issues/1214
There’s plenty decent enough ways users can do this if they’re really keen. Eg. subclass
StaticFiles
and override theget_directories
method.It’s okay for us to just default to one directory + packages.