[英]How to pass variables to a view in Express?
I am quite new to Express.js/Node.js and trying to pass multiple values from a route to a view so that I am able to show user specific input on the page. 我是Express.js / Node.js的新手,并尝试将多个值从路径传递到视图,以便我能够在页面上显示用户特定的输入。 This is what I have in my route:
这就是我的路线:
// Dashboard for site after the login
app.get('/dashboard', function(req, res) {
res.render('dashboard.jade', {
title: 'Dashboard',
user: app.get('user_name')
});
});
I have stored the user name in app.get('user_name')
. 我已将用户名存储在
app.get('user_name')
。 If I replace it with a normal string like 'test string'
than it works. 如果我用普通的字符串替换它,比如
'test string'
不是它的工作原理。 But if I use this app.get
function nothing is getting passed to the view. 但是,如果我使用这个
app.get
函数,则没有任何内容传递给视图。
Thanks 谢谢
尝试使用此处记录的app.locals: http ://expressjs.com/api.html#app.locals
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.