如何写“用户名”仪表盘页面上?的NodeJS

问题描述 投票:0回答:1

我做了一个登录系统,当用户登陆我想写他的仪表盘上的用户名。

我尝试:

<h2 class="page-header">Dashboard</h2>
<p>Welcome to your dashboard {{username}}</p>

但它不工作

router.post('/register', (req, res) => {
    var name = req.body.name;
    var username = req.body.username;
    var email = req.body.email;
    var password = req.body.password;
    var password2 = req.body.password2;

    // VALIDATION
    req.checkBody('name','Name is required').notEmpty();
    req.checkBody('username','Username is required').notEmpty();
    req.checkBody('email','Email is required').notEmpty();
    req.checkBody('email','Email is not valid').isEmail();
    req.checkBody('password','Password is required').notEmpty();
    req.checkBody('password2','Passwords do not match').equals(req.body.password);
)} 

我能做什么 ?

html node.js handlebars.js
1个回答
0
投票

你所要做的是与用户名渲染视图作为本地variable.This可以用快递res.render()函数来完成。例如:res.render('view',{username: ''});.You可以更好地理解看看这个文件 - https://expressjs.com/en/api.html#res.render

© www.soinside.com 2019 - 2024. All rights reserved.