You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Handlebars表单POST请求返回404错误排查求助

404 Error When Submitting Update Contact Form (Valid ID Provided)

Hey there, let's work through why you're hitting that 404 error even with a valid contact ID!

The first thing that jumps out is a tiny but critical mistake in your Express route configuration: your POST route path is missing the leading slash /.

In Express, routes without a leading slash are treated as relative paths, which means your server isn't matching the POST request to /contacts/34634234 with your handler. That's exactly why you're getting a 404 error.

Fix the Route Path

Update your Node route code to include the leading slash:

router.post('/contacts/:id', function(req, res) { 
  res.render('index'); 
});

Quick Additional Checks (Just to Be Thorough)

  • Double-check that your Handlebars template is rendering the form's action correctly. View the page source in your browser to confirm it shows something like <form method="POST" action="/contacts/34634234"> (no typos in the ID or path).
  • Make sure this router is properly mounted to your Express app (e.g., via app.use('/', yourRouter) — if you mounted it under a different path like /api, you'd need to adjust your form's action accordingly, but based on your description this probably isn't the case).

Since you confirmed res.render('index') works elsewhere, fixing that leading slash in the route should resolve the 404 issue right away!

内容的提问来源于stack exchange,提问作者MickeyTheMouse

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:12:17