【问题标题】:Req.params of EJS doesn't work with ExpressEJS 的 Req.params 不适用于 Express
【发布时间】:2015-09-21 17:20:12
【问题描述】:

我来这里是因为我创建了一个快速应用程序并使用

app.get('/admin/edit/articles/:id', function(req, res) {
var Article = require(__dirname + '/models/article.js');

if(req.params.id != null || req.params.id != '') {
  Article.findById(req.param('id'), function(err, result) {
    console.log(result);
  });
  res.render('admin/articles/edit', {id: req.params.id, title: result.local.title, content: result.local.content});
}
});

当我转到 /admin/edit/articles/234 时,它会返回

无法获取 /admin/edit/articles/234

我使用 EJS(~0.8.5)Express(~4.0.0)Mongoose(~3.8.1)

期待看到你的回答

【问题讨论】:

  • 您需要将res.render 调用放在findById 回调中。
  • 在 app.get 行上方发布您使用 app 所做的所有事情。另外,响应码是什么? 404?
  • 你确定你的快递服务器真的在运行吗? app.get() 回调中的 console.log() 语句是否得到输出?
  • 另外,尝试req.params['id'],并添加一个发送res.status(404).send()} else { 块,因为如果不满足条件,请求将挂起

标签: node.js express mongoose params ejs


【解决方案1】:

对不起,我忘记了网址中的“s”。

感谢一切。

【讨论】:

    猜你喜欢
    • 2015-07-05
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    • 2019-11-10
    • 2019-02-03
    • 2017-12-24
    • 2015-08-29
    • 1970-01-01
    相关资源
    最近更新 更多