如何在渲染html页面中检索nodejs会话值?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在渲染html页面中检索nodejs会话值?相关的知识,希望对你有一定的参考价值。

我需要在注册页面中访问此用户名。以下代码无效。你能说一下需要做什么吗?

  app.post('/login', function (req, res) {
    if(req.body.username === "ms" || req.body.password === "ms") {
     sess=req.session;
     req.session.password = req.body.password;
     req.session.username = req.body.username;      
     res.render('/registration.html', { username:req.user.username });
  }
 });
答案

我建议你使用像pug这样的模板引擎。

使用此方法,您将能够发送JSON数据并呈现视图

希望能帮助到你。

以上是关于如何在渲染html页面中检索nodejs会话值?的主要内容,如果未能解决你的问题,请参考以下文章