【发布时间】:2017-12-08 03:06:34
【问题描述】:
我已经尝试了很长时间来加载 CSS 文件。我看过其他stackoverflow问题,但没有运气。我有 express.static 语句。我有“标准”文件顺序。看来我在做一些非常明显的错误。
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<nav>
<ul>
<li class="inline"><a class="inline" target="_blank" href="http://instagram.com/blakskyben/?hl=en">My Insta</a></li>
<li class="inline"><a class="inline" href="/about">About Me</a></li>
<li class="inline"><a class="inline" href="/">Blogs</a></li>
</ul>
</nav>
___________________________________________________________________________
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
mongoose = require("mongoose");
mongoose.connect("mongodb://localhost/blog");
var blogSchema = new mongoose.Schema({
title: String,
content: String
});
app.use(express.static("public"));
app.use(express.static("partials"));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.get("/",function(req,res){
res.redirect("/blogs");
});
app.get("/blogs",function(req,res){
blog.find({},function(err,foundBlogs){
if(foundBlogs){
res.render("blogs.ejs",{blogs: foundBlogs});
} else {
res.send("Sorry, an error occured retriving the blogs, " + err);
}
});
});
app.get("/blogs/:id",function(req,res){
blog.findById(req.params.id,function(err,foundBlog){
if(foundBlog){
res.render("show.ejs",{blog: foundBlog});
} else {
res.send("Sorry, but there was an error, " + err);
}
});
});
app.get("/about",function(req,res){
res.render("about.ejs");
});
var blog = mongoose.model("blog",blogSchema);
//Seed the DB!
blog.create({
title: "Camp",
content: "Blah."
});
app.listen(8080);
【问题讨论】:
-
style.css是否存在于您的项目目录中? -
它位于公共文件夹内的 CSS 文件夹中。
标签: javascript html css node.js