簡體   English   中英

在 NODE.JS 中鏈接 CSS、HTML

[英]Linking CSS, HTML IN NODE.JS

我正在嘗試為使用 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>

styles.css

body {
    color:red;
}
<link rel="stylesheet" href="/css/styles.css"/>

只需從鏈接中刪除 type="css"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM