英文:
Html Image will not load under any change - Golang
问题
我正在尝试在我的HTML页面上加载本地图片。我首先尝试通过**/images/文件夹来提供图片路径,但没有成功。然后我尝试使用完整的图片路径来提供图片,像这样:<img src="/Users/code/src/code/go/src/websites/website/website-Bucket.png" alt="test">
,但仍然没有成功。我检查了我的HTML,没有错误。我已经重新启动了我的电脑**,将图片更改为**.jpg**格式,但仍然无法工作。在Safari中,我收到一个错误消息 - 尝试加载资源时发生错误,图片显示为蓝色方框和问号。你会尝试哪些方法来进行故障排除?
额外信息 - 我正在使用Go语言来提供文件。我已经设置了一个http.handleFunc(),当请求时会去提供images文件夹。路径显示为http://localhost/images/theImage.png,是正确的路径,但什么都没有发生。所以,我保存了图片,它显示为一个HTML,并显示页面的一部分?这可能是路径的问题吗?
英文:
I am trying to load an image locally onto my html. I first tried serving an image path through a /images/ folder, but that did not work. I then tried serving images with the whole path to the image like <img src="/Users/code/src/code/go/src/websites/website/website-Bucket.png" alt="test">
but I still had no luck. I checked my html and it has no errors. I have restarted my PC, changed the image to .jpg, and it still did not want to work. I get an error in Safari - An error occurred while trying to load the resource and the image shows as a blue box and question mark. What things would you try to troubleshoot?
Extra - I am using goLang to serve the files. I have it so a http.handleFunc() goes off and serves the images folder when it is requested. The path is showing http://localhost/images/theImage.png "the correct path" but nothing happens. So, I save the image and it shows it as a html and shows a section of the page?? Would that be a path thing?
答案1
得分: 1
看起来可能是文件路径的问题。
<br>看一下这个页面,它有一个很好的例子。<br>
https://www.w3schools.com/html/html_filepaths.asp<br>
<br>
另外,尝试使用下划线(_)重命名图像,而不是使用破折号(-)。
英文:
Looks like it may be a file path issue.
<br>Take a look at this page it has a good example.<br>
https://www.w3schools.com/html/html_filepaths.asp<br>
<br>
Also try renaming the image with a _ and not use the -.
答案2
得分: 1
首先,你需要理解路径源。当你在一个HTML文件中时,文件内部的路径应该是这样的:
<img src="images/website-Bucket.png" alt="test">
这是因为:
你的.html文件的路径可以通过文件内部的路径访问,使用"/文件夹/文件"的结构路由在HTML文件中,所以你的文件结构应该是:
- yourfile.html(在浏览器上呈现的文件)/images文件夹
-
- website-Bucket.png(你在HTML中调用它时是/images文件夹/website/Bucket.png)。
你可以在这里了解更多关于路径的信息:
http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/
英文:
In first instance you have to understand the path source, when you are on a HTML file, your path inside the file should be :
<img src="images/website-Bucket.png" alt="test">
that's because :
the path of your .html file can access trough files the inside path with the "/folder/file" structure route in the html file, so your structure files should be:
-
yourfiel.html (your file render on browser) /imagesfolder
-
-website-Bucket.png" (you call it on your html as
-
/imagesfolder/website/Bucket.png)./
you can learn more about paths here :
http://www.coffeecup.com/help/articles/absolute-vs-relative-pathslinks/
答案3
得分: 1
请在任何浏览器中打开控制台,并查看是否有任何错误提示,提到无法找到图片的源路径。
这应该会给你一个提示,告诉你浏览器试图在哪里找到该图片。
英文:
Open Console in any browser and see if you see any errors that mention not being able to find the source path of the picture.
It should give you a hint of where your browser is trying to find that img.
答案4
得分: 1
你们所有人的回答都是正确的。我找到了正确的路径。这是一个 Golang 的问题。当服务器需要 /image.png 时,我没有创建 handlefunc。它从未提供图像,只是无动作。谢谢你们的回答。
英文:
All of your guy's responses were correct. I had the correct path. It was a Golang thing. I did not make a handlefunc when the server wants the /image.png. It was never serving the image, it just was doing nothing with it. Thank you for the responses.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论