When mounting static files, the order of operations is important.
Your environment
Python 3.11.3
Manjaro Linux
Steps to reproduce
Putting a file in images and then trying to open it, e.g. http://127.0.0.1:8000/images/foo.png does not work.
# Mount static files so that we can include screenshots in the documentation
app.mount("/images", StaticFiles(directory="images"), name="images")
# Setup API versioning
versions = Versionizer(
app=app,
prefix_format='/v{major}',
semantic_version_format='{major}',
default_version=(1, 0),
sort_routes=True
).versionize()
Expected behaviour
Static file mounts should be accessible.
Actual behaviour
Static files won't be accessible and one gets {"detail":"Not Found"}
# Setup API versioning
versions = Versionizer(
app=app,
prefix_format='/v{major}',
semantic_version_format='{major}',
default_version=(1, 0),
sort_routes=True
).versionize()
# Mount static files so that we can include screenshots in the documentation
# This *has* to be called after Versionizer otherwise it will not work
app.mount("/images", StaticFiles(directory="images"), name="images")
I'm not entirely sure this is actually an issue, but maybe something that should be documented (happy to create a PR). If nothing else, this issue might help somebody coming across the same problem like I had.
Subject of the issue
When mounting static files, the order of operations is important.
Your environment
Steps to reproduce
Putting a file in
images
and then trying to open it, e.g.http://127.0.0.1:8000/images/foo.png
does not work.Expected behaviour
Static file mounts should be accessible.
Actual behaviour
Static files won't be accessible and one gets
{"detail":"Not Found"}
Workaround
Calling
app.mount
after instantiating Versionizer works.I'm not entirely sure this is actually an issue, but maybe something that should be documented (happy to create a PR). If nothing else, this issue might help somebody coming across the same problem like I had.
@alexschimpf thank you for this great library.