fasthtml icon indicating copy to clipboard operation
fasthtml copied to clipboard

[BUG] Cannot change the static media route without removing the default route.

Open coreman14 opened this issue 6 months ago • 0 comments

In the documentation, the given example for how to change the static media file location is given as:

@rt("/{fname:path}.{ext:static}")
async def get(fname:str, ext:str): 
    return FileResponse(f'public/{fname}.{ext}')

But because this exact same route is defined when you call fast_app(), the user cannot change the location of the static media.

You can currently get around this issue by running app.routes.pop() which will remove the default static media route, so you can now redefine the route with the correct folder location.

An argument could be added when the fast_app is created allowing the user to override the static file location.

app, rt = fast_app(static_file_location="public/")

coreman14 avatar Aug 22 '24 22:08 coreman14