gpt4 book ai didi

node.js - 如何将变量传递给 Express 中的 View ?

转载 作者:搜寻专家 更新时间:2023-10-31 22:46:18 25 4
gpt4 key购买 nike

我是 Express.js/Node.js 的新手,我试图将多个值从路由传递到 View ,以便我能够在页面上显示用户特定的输入。这是我的路线:

// Dashboard for site after the login
app.get('/dashboard', function(req, res) {
res.render('dashboard.jade', {
title: 'Dashboard',
user: app.get('user_name')
});
});

我已将用户名存储在 app.get('user_name') 中。如果我用 'test string' 之类的普通字符串替换它,它就会起作用。但是,如果我使用此 app.get 函数,则不会将任何内容传递给 View 。

谢谢

最佳答案

尝试使用此处记录的 app.locals:http://expressjs.com/api.html#app.locals

关于node.js - 如何将变量传递给 Express 中的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14149252/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com