在Heroku上找不到的Jade模板

在本地运行此 Express应用程序。 在Heroku上运行时,在请求//nested时会出现粘贴错误

 Error: Failed to lookup view "index" at Function.app.render (/app/node_modules/express/lib/application.js:493:17) at ServerResponse.res.render (/app/node_modules/express/lib/response.js:753:7) at /app/server.js:21:16 at callbacks (/app/node_modules/express/lib/router/index.js:161:37) at param (/app/node_modules/express/lib/router/index.js:135:11) at pass (/app/node_modules/express/lib/router/index.js:142:5) at Router._dispatch (/app/node_modules/express/lib/router/index.js:170:5) at Object.router (/app/node_modules/express/lib/router/index.js:33:10) at next (/app/node_modules/express/node_modules/connect/lib/proto.js:199:15) at store.get.next (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:309:9) Error: Failed to lookup view "nested/index" at Function.app.render (/app/node_modules/express/lib/application.js:493:17) at ServerResponse.res.render (/app/node_modules/express/lib/response.js:753:7) at /app/server.js:24:16 at callbacks (/app/node_modules/express/lib/router/index.js:161:37) at param (/app/node_modules/express/lib/router/index.js:135:11) at pass (/app/node_modules/express/lib/router/index.js:142:5) at Router._dispatch (/app/node_modules/express/lib/router/index.js:170:5) at Object.router (/app/node_modules/express/lib/router/index.js:33:10) at next (/app/node_modules/express/node_modules/connect/lib/proto.js:199:15) at store.get.next (/app/node_modules/express/node_modules/connect/lib/middleware/session.js:309:9) 

在我的服务器文件中:

 express = require 'express' app = express() app.configure () -> app.set 'views', __dirname + '/views' app.set 'view engine', 'jade' app.use express.logger('dev') app.use express.bodyParser() app.use express.methodOverride() app.use express.cookieParser() app.use express.session( secret: 'WTF' ) app.use app.router app.use express['static'](process.cwd() + '/public') app.get '/', (req, res) -> res.render 'index' app.get '/nested', (req, res) -> res.render 'nested/index' port = process.env.PORT || 3000 app.listen port, () -> console.log 'Server started on ' + port + '\nPress CTRL-C to stop server.' 

在本地,我不需要指定app.set 'views', __dirname + '/views'来运行服务器并find这些文件 – 它不能在Heroku上使用或不使用。

       

网上收集的解决方案 "在Heroku上找不到的Jade模板"

关于你的编辑:

这个问题可能是案例。 string指定小写path:

  • res.render 'index'
  • res.render 'nested/index'

这些文件实际上是大写的:

  • views/Index.jade
  • views/nested/Index.jade

您的本地系统似乎使用不区分大小写的文件系统,而Heroku则不使用。



为了帮助快速查找您的意见,您可以设置一个'views'根path:

 app.set('views', __dirname + '/views'); 

您也可以将绝对path传递给res.render()

 res.render(__dirname + '/views/admin/login'); 

另外请注意,您可能不需要(也可能不想)将reqres传递给res.render()

 app.get('/admin/login', function (req, res) { res.render('admin/login'); }); 

有了它们, req的属性将被包含在视图和res因为callback将被忽略或导致错误,因为它不是一个function