expressjs可以做两个post路线吗?

我创build了一个Expressjs应用程序。 它包含公共,视图,路线文件夹和app.js文件。

我有一个post路由器“/”path像这样在app.js中,

app.post('/', store.home_post_handler); 

和玉码,

 #display #login form(method='post') | Enter your name if you want to be a ninja div input(type='text', name='username') input(type='submit', value='Log In') 

我的问题是,是否有可能在一个页面中有两个post方法?

如果你想在客户端页面上使用两种表单来做不同的事情,区分表单的最简单的方法是通过改变表单元素的action属性来让它们POST到不同的URL。

如果您需要将表单发布到相同的URL,您应该使用@hexacyanide的解决scheme。

 // app.js app.get('/form', function(req, res){ res.render('formTemplate'); }); app.post('/form1', function(req, res){ console.log(req.body.foo); }); app.post('/form2', function(req, res){ console.log(req.body.bar); }); // formTemplate.jade !!! body form(action='form1', method='post') label(for='foo') Foo: input(type='text', name='foo', id='foo') input(type='submit', value='Submit Foo') form(action='form2', method='post') label(for='bar') Bar: input(type='text', name='bar', id='bar') input(type='submit', value='Submit Bar')