javascript - 带有大于 (>) 符号的 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") %>
解决方案
您>
错误地包括在内。它应该是
<h1><%=post.PostTitle%></h1>
<p><%=post.Content%></p>
不是
<h1>><%=post.PostTitle%></h1>
<p>><%=post.Content%></p>
推荐阅读
- c++ - 为什么在 operator delete 中没有调用析构函数?
- amazon-web-services - Amazon EC2 错误“警告:未受保护的私钥文件!” 即使更改了 Microsoft WSL 的权限
- c# - 隔离 IDistributedCache DI 消耗
- javascript - 我无法在 reactjs 中将自定义样式设置为 antd Date Picker
- android - 每次我在我的 android studio 项目中修改某些东西时,git hub 都会充满变化
- linkedin - 如何使用 access_token 获取 LinkedIn 个人资料图片
- google-bigquery - BigQuery 表之上的数据洞察,过滤中断数据连接
- c++ - 我的程序在到达“cin << ans1”时崩溃
- azure - 使用 Azure AD 登录用户
- linux - 通过在 rc.local 文件中提供 java-jar 命令在 CentOS 上执行 selenium 脚本