-
-
Notifications
You must be signed in to change notification settings - Fork 956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple directories in StaticFiles #625
Comments
Good summary on this issue, yup! |
We can now add the |
Any news on this? |
@aminalaee you've been creating some PRs around |
@Kludex yeah. It does make sense. There is no conclusion about the API for it. Honestly I don't think this is very nice: static_app = StaticFiles(directory="static")
static_app.add_directory("another_static_dir") We did handle multiple directories for third party packages: StaticFiles(packages=[('bootstrap4', 'static')]) But for local directories I think we can work around it. |
Could we accept both |
Closing with the same rationale as #1214 There's plenty decent enough ways users can do this if they're really keen. Eg. subclass It's okay for us to just default to one directory + packages. |
fyi, I used the following solution : import typing
from starlette.staticfiles import PathLike, StaticFiles
class MultiStaticFiles(StaticFiles):
def __init__(self, directories: typing.List[PathLike] = [], **kwargs) -> None:
super().__init__(**kwargs)
self.all_directories = self.all_directories + directories |
The 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 toStaticFiles
app, to allow adding multiple directories to the the sameStaticFiles
app and it can be used like so :We can also add
add_directories
which accepts a list of directoriesadd_directory
Allow adding directories to StatiFiles app #6262- 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 kwargdirectories: List[str]
, I'm also aware it's not a good idea :3 (even worse) to expose two ways of doing thingsdirectory
anddirectories
but the way of implementing it should be discussed, ofc if accepted.The text was updated successfully, but these errors were encountered: