【问题标题】:Express and ejs快递和ejs
【发布时间】:2021-09-21 08:56:15
【问题描述】:

我最近开始学习 EJS 和 Express。

这是我的 app.js 文件:

   let app = express();
   
   app.set('view engine', 'ejs');
   
   app.get('/', (req, res) => {
     res.render('index');
   });
   app.get('/fallinlovewith/:thing',(req,res)=>{
       var name = req.params.thing;
    res.render('love',{name:name});
   });
   app.listen(3000, () => console.log('Example app listening on port 3000!'));

这是我的 index.ejs 和 love.ejs 文件: index.ejs:

<h1>This is succesful !</h1>

love.ejs:

<h1>You fell in love with :</h1>
<p>This is from love.ejs folder</p>

我的代码能够渲染 index.ejs 文件,但不能渲染 love.ejs 。 love.ejs 显示以下文本而不是正常的标题和段落。 This is what is being displayed at http://localhost:3000/fallinlovewith/dipti 我不知道这些“问号”符号表示什么。 我被困在这里。有人可以帮忙吗?

【问题讨论】:

    标签: html node.js express ejs web-development-server


    【解决方案1】:

    尝试在 html 中指定语言和字符集:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        ...
    

    【讨论】:

      猜你喜欢
      • 2020-04-19
      • 1970-01-01
      • 2019-05-26
      • 2015-08-11
      • 1970-01-01
      • 2016-10-06
      • 2013-05-06
      • 2017-05-23
      • 2018-04-09
      相关资源
      最近更新 更多