当添加ejs模板时,本地主机没有响应。

问题描述 投票:0回答:1

当在页面中添加partials(ejs模板)时,本地主机无法加载.如果不添加partials,页面一开始就会加载,但一旦添加partials,页面就不再加载,也没有错误报告,页面一直在加载,最后显示无法到达地址。

var express = require("express");
var app = express();
var bodyparser = require("body-parser");

app.use(bodyparser.urlencoded({extended: true}));
app.set("view engine", "ejs");


app.get("/", function(req , res){
    res.render("landing");
});

app.get("/campgrounds", function(req,res){
   res.render("campgrounds",{campgrounds:campgrounds});
});

app.post("/campgrounds",function(req,res){
    var name = req.body.name;
    var image = req.body.image;
    var newCamp = {name: name, image:image}
    campgrounds.push(newCamp)
    res.redirect("/campgrounds");
});

app.get("/campgrounds/new", function(req, res){
    res.render("new.ejs");
});
app.listen(3000, function(){
    console.log("Yelp camp server has started");
});

当在下面的页面中添加页眉时,页面不再加载。

 <%- include('partials/header.ejs') %>

<h1>landing page</h1>

<a href="/campgrounds">view all campgrounds</a>
<p>asdasdasda</p>

<%- include('partials/footer.ejs') %>

请大家帮忙!!!另外这里是头的代码。

    <!DOCTYPE html>
<html>
    <head>
        <title>YELPCAMP</title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" >
    </head>

<body>
<p>header tabs</p>
node.js express ejs
1个回答
0
投票

你错过了一个 - 从关闭标签。

<%- include('partials/header.ejs') -%>

...

<%- include('partials/footer.ejs') -%>

0
投票

谢谢你的帮助 ,问题的发生是因为一个不正确的bootstrap cdn和partials声明.修复了这些问题,现在应用程序工作正常。

© www.soinside.com 2019 - 2024. All rights reserved.