Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Discussion options

You must be logged in to vote

Hello @skewty,
for your specific case, simply specify an empty path parameter should solve your issue.

from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles

app = FastAPI()
app.mount("/static", StaticFiles(directory="/var"), name="test")
app.url_path_for("test", path="") # proably you have to trail the last backslash

Consider this as a little work around, since seems that StaticFiles is not totally supported from url_path_for.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Comment options

You must be logged in to vote
2 replies
@luzzodev
Comment options

luzzodev May 3, 2025
Collaborator

@YuriiMotov
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants