首页 > 解决方案 > 带有大于 (>) 符号的 EJS HTML 渲染

问题描述

**在我转到根路径后,h1 和段落被渲染,但它呈现 > 符号任何解决方案我正在学习一门课程,在该课程中,讲师执行所有以下过程并获得所需的输出,但它没有 >象征 **

const express = require("express");
const bodyParser = require("body-parser");
const ejs = require("ejs");
var posts = [];
const app = express();

app.set('view engine', 'ejs');

app.get("/", function(req, res){
  res.render("home", {Content : homeStartingContent, posts: posts});
  
});
app.get("/compose", function(req, res){
  res.render("compose");
});

app.post("/compose",bodyParser.urlencoded({extended: true}),function(req, res){
  let Post = {
    PostTitle: req.body.Title,
    Content: req.body.Content, 
  };
  posts.push(Post);
  res.redirect("/");
  
});


app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("public"));

app.listen(3000, function() {
  console.log("Server started on port 3000");
});
<%- include("Partials/header") %>

<h1>Home</h1>
<p><%= Content %></p>



    <% posts.forEach(function(post){ %>
    <h1>><%=post.PostTitle%></h1> 
    <p>><%=post.Content%></p> 
 <%   }); %>


<%- include("Partials/footer") %>

标签: javascriptnode.jsejs

解决方案


>错误地包括在内。它应该是

<h1><%=post.PostTitle%></h1> 
<p><%=post.Content%></p>

不是

<h1>><%=post.PostTitle%></h1> 
<p>><%=post.Content%></p>

推荐阅读