`app.static` report an error
David-xian66 opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
One of my projects that needs to render files (vue bundled HTML, etc.)
I just set up the folder for convenience.
An error occurred after I set root_bp.static("/css/", "./HTML/css")
Error:
C:\Users\Administrator\AppData\Local\Programs\Python\Python311\Lib\site-packages\sanic\log.py:133: DeprecationWarning: [DEPRECATION v23.3] Duplicate route names detected: MSS_Back.root.static. In the future, Sanic will enforce uniqueness in route naming.
warn(version_info + message, DeprecationWarning)”
But after I tested it, I found that the file under css
can be accessed normally
Code snippet
root_bp.static("/css/", "./HTML/css")
Expected Behavior
No response
How do you run Sanic?
Sanic CLI
Operating System
Windows Server 2022 Datacenter
Sanic Version
Sanic 22.12.0; Routing 22.8.0
Additional context
No response
Name your routes, like it suggests:
root_bp.static("/css/", "./HTML/css", name="static.css")
The default name for static files is simply static
and you can only have one route by that name. It still works but you get a deprecation warning because in the future this will be an error.
Name your routes, like it suggests:
root_bp.static("/css/", "./HTML/css", name="static.css")The default name for static files is simply
static
and you can only have one route by that name. It still works but you get a deprecation warning because in the future this will be an error.
So, if there are multiple files in the CSS folder, how can I add multiple files at once
You can just serve the directory of css files. I think you are just confused because the name @Tronic chose looks like a filename, but is not really.
root_bp.static("/css/", "./HTML/css", name="anything-can-be-here")