这是我的密码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home Page</title>
</head>
<body>
<img src="resources/mainlogo.png" style="width:304px;height:228px;">
<h1>Welcome to our user management application</h1>
<h3>Please see links below to navigate our homepage</h3>
<a href = /adduser>Create new user</a>
<a href = /users>List users</a>
</body>
</html>
除了图像之外,所有的图像都显示出来了。
以下是我的文件结构:
index.html
resources
mainlogo.png
我做错了什么?
这是渲染代码
app.get('/', function (req, res) {
// render main page
res.sendFile(__dirname + "/index.html");
});
这里还有来自控制台的错误
Error http://localhost:8000/resources/mainlogo.png 404 (Not Found)
尽管图像在资源文件夹中。
发布于 2017-02-12 11:59:00
您需要通过express.static
访问资源文件夹。这应该能起作用:
app.use(express.static('resources')); //This will allow express to access any file in that folder
Html:
...
<img src="mainlogo.png" style="width:304px;height:228px;">
...
发布于 2017-02-12 11:57:30
加法
app.use(express.static('resources'))
改变这一切
<img src="mainlogo.png" style="width:304px;height:228px;">
有帮助
发布于 2017-02-12 12:03:15
您需要使用express.static
中间件来提供静态文件,如图像和CSS文件。
在你的例子中,这应该是可行的:
app.use(express.static('resources'));
查看显示静态文件的静态文档
https://stackoverflow.com/questions/42192404
复制