[英]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.