javascript - 切换页面,为什么我routes里面req.session.userid存在,却无法在客户端上显示<%=userid%>的值?
迷茫
迷茫 2017-04-17 16:32:40
0
2
347
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(2)
Peter_Zhu

The userid is given in roomview.html: roomview.html里给了userid

res.render('roomview', {
    userid: req.session.userid,
    rooms:docs
});

addroom.html的路由里你没写:

res.render('addroom.html')

所以自然找不到。

如果你希望ejs里可以直接获取session里的信息,可以尝试使用locals,比如前置一个中间件:

app.use(function(req, res, next) {
  res.locals.userid = req.session.userid;
  next();
});

这样,你的ejs模版里就可以直接使用<%= userid %> rrreee

And you didn’t write in the route of addroom.html: 🎜 rrreee 🎜So naturally I can’t find it. 🎜 🎜If you want ejs to directly obtain the information in session, you can try to use locals, such as prefixing a middleware: 🎜 rrreee 🎜In this way, you can directly use <%= userid %> in your ejs template🎜
伊谢尔伦

The pictures I drew are quite beautiful

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template