【发布时间】:2012-11-09 07:48:02
【问题描述】:
我正在尝试为模板制作一个带有 node、express 和 ejs 的简单服务器。我已经让服务器指向页面,加载它,甚至可以使用 include 语句生成其他代码。但是由于某种原因,样式表不会加载。
app.js
var express = require('express'),
app = express(),
http = require('http'),
server = http.createServer(app),
fs = require('fs');
var PORT = 8080;
app.set('view engine', 'ejs');
app.get('/', function(req, res){
res.render('board.ejs', {
title: "anything I want",
taco: "hello world",
something: "foo bar",
layout: false
});
});
app.listen(PORT);
console.log("Server working");
ejs 文件在目录views/board.ejs 中
<html>
<head>
<title><%= title %></title>
<link rel='stylesheet' href='../styles/style.css' />
</head>
<body >
<h1> <%= taco %> </h1>
<p> <%= something %> </p>
</body>
</html>
style.css 位于相对于 app.js 的 styles/style.css 目录中
p {
color:red;
}
对于链接的 href,我已经尝试了所有可以想到的路径,包括相对于我的 localhost 相对于 app.js 相对于 board.ejs 指向的位置,甚至只是 style.css,但似乎没有一个有效。非常感谢任何建议。
【问题讨论】:
标签: node.js express stylesheet ejs