简体   繁体   English

加载资源失败:服务器响应状态为 404 (Not Found) Express

[英]Failed to load resource: the server responded with a status of 404 (Not Found) Express

This file contain the file structure该文件包含文件结构

This file contains the directory settings此文件包含目录设置

While trying to add static images to the home.ejs folder i am constantly getting this error:-在尝试将 static 图像添加到 home.ejs 文件夹时,我不断收到此错误:-

Failed to load resource: the server responded with a status of 404 (Not Found)加载资源失败:服务器响应状态为 404(未找到)

I tried to use the app.use(express.static('public')) but the issue still persist.我尝试使用app.use(express.static('public'))但问题仍然存在。

This is the path i used:这是我使用的路径:

assets/img/hero.jpg

I cannot figure out how to solve this issue and is there is something wrong with file structure or i made mistake while referencing the file name.我不知道如何解决这个问题,是文件结构有问题还是我在引用文件名时出错了。

First we need to set the path首先我们需要设置路径

app.set('/views',path.join(__dirname,'/views'))

then we can use image by using this path:然后我们可以通过使用这个路径来使用图像:

img/hero.jpg

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “无法加载资源:服务器响应状态为404” express docker - “Failed to load resource: the server responded with a status of 404” express docker Node.js服务器:无法加载资源:服务器以状态404(未找到)响应 - Nodejs server: Failed to load resource: the server responded with a status of 404 (Not Found) 加载资源失败:服务器响应状态为 404(未找到) - Ionic2 - Failed to load resource: the server responded with a status of 404 (Not Found) - Ionic2 Heroku:无法加载资源:服务器以状态404(未找到)响应 - Heroku: Failed to load resource: the server responded with a status of 404 (Not Found) 加载资源失败:服务器以 404(未找到)状态响应 nodejs - Failed to load resource: the server responded with a status of 404 (Not Found) with nodejs 无法加载资源:服务器响应状态为 404(未找到),显示在控制台上 - Failed to load resource: the server responded with a status of 404 (Not Found) displayed on console ReactJS Heroku 部署错误:无法加载资源:服务器响应状态为 404(未找到) - ReactJS Heroku Deployment Error: Failed to load resource: the server responded with a status of 404 (Not Found) “加载资源失败:服务器响应状态为 404(未找到)”+“来源……访问控制允许来源不允许。” - "Failed to load resource: the server responded with a status of 404 (Not Found)" + "Origin … is not allowed by Access-Control-Allow-Origin." 加载资源失败:服务器响应状态为 404(未找到),而我的后端接受请求 - Failed to load resource: the server responded with a status of 404 (Not Found) while my backend accepts the request 节点js响应加载资源失败:服务器响应状态为404(未找到) - Node js response Failed to load resource: the server responded with a status of 404 (Not Found)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM