EJS HTML 使用大于 (>) 符号渲染
EJS HTML Render With Greater Than (>) Symbol
** 在我转到根路径后,h1 和段落得到呈现,但它呈现为 > Symbol Any Solution 我正在学习一门课程,在该课程中,讲师执行以下所有过程并获得所需的输出但是它没有 > 符号 **
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") %>
您错误地包含了 >
。
应该是
<h1><%=post.PostTitle%></h1>
<p><%=post.Content%></p>
没有
<h1>><%=post.PostTitle%></h1>
<p>><%=post.Content%></p>
这是你的问题
<% posts.forEach(函数(post){ %>
<h1>><%=post.PostTitle%></h1>
^
<p>><%=post.Content%></p>
<%}); %>
** 在我转到根路径后,h1 和段落得到呈现,但它呈现为 > Symbol Any Solution 我正在学习一门课程,在该课程中,讲师执行以下所有过程并获得所需的输出但是它没有 > 符号 **
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") %>
您错误地包含了 >
。
应该是
<h1><%=post.PostTitle%></h1>
<p><%=post.Content%></p>
没有
<h1>><%=post.PostTitle%></h1>
<p>><%=post.Content%></p>
这是你的问题
<% posts.forEach(函数(post){ %>
<h1>><%=post.PostTitle%></h1>
^
<p>><%=post.Content%></p>
<%}); %>