html - 在 NODE.JS 中链接 CSS、HTML
问题描述
我正在尝试为我使用 Node.js 制作的一个非常简单的应用程序添加一些样式。我尝试了所有可能的答案,但 CSS 文件继续没有出现。如果有人可以帮助我发现错误,我会很高兴:) 提前致谢。
我在 goormIDE 工作。
我的文件夹:
>app.js
>public
>css
>styles.css
>views
>search.ejs
我在 app.js 中的代码
var express = require("express");
var app = express();
var request = require("request");
app.use(express.static(__dirname + '/public'));
app.set("view engine", "ejs");
app.get("/", function(req, res){
res.render("search");
});
app.get("/results", function(req, res){
var query = req.query.search;
var url = "http://omdbapi.com/?s=" + query + "&apikey=thewdb";
request(url, function(error, response, body){
if(!error && response.statusCode == 200) {
var data = JSON.parse(body);
res.render("searchresults", {data: data});
}
});
});
app.listen(9000, function(){
console.log("Movie App has started!!!");
});
搜索.ejs:
<!DOCTYPE html>
<html>
<head>
<title>Central Cinema</title>
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<link rel="stylesheet" type="css" href="/css/styles.css"/>
</head>
<body>
<div class="container">
<div class="landing-header">
<h1>Search For a Movie</h1>
<form action="/results" method="GET">
<input type="text" placeholder="search term" name="search">
<input type="submit">
</form>
</div>
</div>
</body>
样式.css
body {
color:red;
}
解决方案
<link rel="stylesheet" href="/css/styles.css"/>
只需从链接中删除 type="css"
推荐阅读
- c++ - 堆栈内存的起始地址是什么?
- r - 将带有空格的数据转换为数据框
- function - 将表达式重新排列为传递函数的标准形式
- java - 如何在基于 Maven 的 Java Web 应用程序中查找 .properties 文件?
- angular - Angular Router:导航到上一个路由转义字符
- python - 为什么这段代码不跳过文件的第一行?
- express - 页面刷新或直接加载显示黑屏
- javascript - 有没有办法告诉事件循环处理 ES5 中的下一条消息?
- php - 从外部 FTP 服务器读取 > 1GB GZipped CSV 文件
- flutter - 使用 TextField 控制器 Flutter HTTP POST 请求