问题
I have an url like this: http://localhost/editblog/58a5da1df3ec9614fc9893d3
and code in pug like this:
input.form-control(type='hidden', name='id', value='')
The question is how to get the value on the url and pass it to value=''
I've known about req.params.id
but it is not what could solve my issue
回答1:
When you render your pug template you could send any variable as res.locals
property so it will send to template:
app.get('/editblog/:id', function(req, res) {
res.render('editblog', { title: 'edit blog', id: req.params.id });
});
And now you have access to id
whithin your template:
editblog.pug:
input.form-control(type='hidden', name='id', value=id)
来源:https://stackoverflow.com/questions/42280831/how-to-get-the-value-on-url-in-pug