question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multiple directories in StaticFiles

See original GitHub issue

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 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 directoriesbut the way of implementing it should be discussed, ofc if accepted.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
pomareccommented, Apr 20, 2022

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
0reactions
tomchristiecommented, Feb 8, 2022

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 the get_directories method.

It’s okay for us to just default to one directory + packages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple Directories for Static Files in ASP.NET Core
My recent video, SPAs in ASP.NET Core Another Attempt, elicited several interesting responses. But immediately, I noticed that using ASP.NET ...
Read more >
How can you use multiple directories for static files in an ...
Is there a way to configure an aspnet core app to use two separate directories for static files? asp.net-core · Share.
Read more >
Mapping Multiple Static File Folders in ASP.NET Core
In ASP.NET it's easy to serve static files by using app.UseStaticFiles() as part of configuration. This simple configuration maps the wwwroot ...
Read more >
Multiple static files directories - Getting Help - Go Forum
In go, we can handle static files, by defining their directory as static directory as shown below: fs := http.FileServer(http.Dir(".
Read more >
Using Multiple Directories To Serve Static Resources In Node ...
And I assumed that only one directory can be set to serve static files and that was that. This was a problem for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found