Skip to content

a question about static file path #2192

Discussion options

You must be logged in to vote

In main.rs: .mount("/static",FileServer::from("./static"))

page in 127.0.0.1:8000/ <script src="static/js/js.js"></script> it is ok

but page in 127.0.0.1:8000/article <script src="static/js/js.js"></script> it is 404 not found

I can add some code to address this issue In main.rs: .mount("/article/static",FileServer::from("./static"))

Just use absolute paths in your HTML:

- <script src="static/js/js.js"></script>
+ <script src="/static/js/js.js"></script>

That will always resolve to the same thing and work anywhere.

But I'd still like to know if there's a more elegant solution, similar to FLASK's url_for function

No, but you can implement it yourself as a template helper. See the dyn…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@779505388
Comment options

Answer selected by 779505388
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2191 on May 19, 2022 01:54.