Add staticfiles packages with directory#1350
Conversation
|
Hi @aminalaee As I understand it, with this PR But I don't think that's what we want. Currently, the behavior is that I'm wondering if we should be considering this API instead: StaticFiles(
directory=..., # An independent directory that's unrelated to `packages` (as currently)
packages=[
"bootstrap4", # Default, resolves to bootstrap4/statics
("whatevs", "dist"), # Explicit subdir, resolves to "whatevs/dist"
],
)And then do: for package in packages or []:
try:
package, statics_directory = package
except ValueError:
statics_directory = "statics"
... |
|
@florimondmanca Yes you are right. I have mixed StaticFiles(
directory="statics",
packages=["bootstrap"],
)And this will look for "statics" directory inside the "bootstrap" package. There's a point we didn't take into account, we don't allow sub directories. StaticFiles(packages=["bootstrap.dir.statics"])I'm happy to change this PR if we have a conclusion. |
|
@aminalaee My API suggestion is on the same line than your second suggestion, yes — allowing to specify a per-package target sub-directory. I'd say let's do a single path item and avoid the problem of dealing with OS-dependent path representation for now, which is why I suggested a "string or 2-tuple" representation. WDYT? |
|
@florimondmanca I was thinking to handle the sub-directories in an OS-independant way before another issue comes up mentioning that. I think that makes sense for now, I'll make |
…ncode/starlette into fix-staticfiles-package-with-directory
|
I left a comment on #1265 in case anyone has practical feedback on this, before we merge and include this in the next Starlette release. |
|
@florimondmanca That looks like it would solve the issue myself and @bram2000 were having in #1265 👍🏻 |
|
I have confused python main.py is ok, when I bundle py to a exe., I even mapping a static folder in the root folder, how to specify this directory value is the best |
|
if. I use this. ,still not found File "/Users/wenke/github/tiktoka-studio-uploader-genius/src/app/fastapiserver.py", line 31, in |
|
If I understand correctly you are shipping your package as an installable, so you would need to use the |
|
if i understand correctly, there is 2 options for me here, src/app/static you should use this, app.mount("/static", StaticFiles(packages=[('src.app','static')]), name="static") the other option is in the root folder of project. app.mount("/static", StaticFiles(directory="static"), name="static") it seems you can have directory and packages both there app.mount("/static", StaticFiles(directory="static",packages=[('src.app','static')]), name="static") |


Closes #1265.
Adds ability to specify directory when using the
packagesargument in StaticFiles.The final API is:
This will look for "statics" directory in "bootstrap4" package and "dist" directory in "mypackage".