我创建了一个登录系统,当用户登录时,我想在仪表板上写他的用户名。
我尝试:
<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);
)}
我该怎么办?
答案 0 :(得分:0)
您要做的是使用用户名作为局部变量来呈现视图。这可以使用express res.render()函数来完成。
例如:res.render('view',{username: ''});
。您可以查看此文档以更好地理解-https://expressjs.com/en/api.html#res.render