天蓬老师2017-04-17 16:34:40
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
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🎜