2016-11-22 51 views
0

這個問題已被問過幾次,但我似乎無法解決這個基於其他答案。所以無論我做什麼我似乎不斷得到Failed to lookup view "API" in views directory "/Users/MYUSER/Desktop/matchmaking/app/views"。即使路徑看起來正確?Jade + express無法在視圖目錄中查找視圖

文件結構

├───app 
│ └───bin 
│ └───models 
│ └───node_modules 
│ └───public 
│ │ └───images 
│ │ └───javascripts 
│ │ └───stylesheets 
│ └───routes 
│ │ └───index 
│ │ └───groups 
│ │ └───index 
│ │ └───users 
│ └───views 
│ │ └───error.jade 
│ │ └───index.jade 
│ │ └───layout.jade 
│ └───app.js 
│ └───package.json 
│ └───config.js 
│ └───upload.js 

app.js

var express = require('express'); 
var path = require('path'); 
var favicon = require('serve-favicon'); 
var logger = require('morgan'); 
var cookieParser = require('cookie-parser'); 
var bodyParser = require('body-parser'); 

var routes = require('./routes/index'); 
var users = require('./routes/users'); 
var games = require('./routes/games'); 
var groups = require('./routes/groups'); 

var jwt = require('jsonwebtoken'); // used to create, sign, and verify tokens 
var config = require('./config'); // get our config file 

var mongoose = require('mongoose'); 
mongoose.Promise = global.Promise; 
mongoose.connect(config.database); // connect to our database 



var app = express(); 

// view engine setup 
app.set('views', path.join(__dirname, 'views')); 
app.set('view engine', 'jade'); 

// uncomment after placing your favicon in /public 
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); 
app.use(logger('dev')); 
app.use(bodyParser.json()); 
app.use(bodyParser.urlencoded({ extended: false })); 
app.use(cookieParser()); 
app.use(express.static(path.join(__dirname, 'public'))); 

app.use('/api', routes); 
app.use('/api/users', users); 
app.use('/api/games', games); 
app.use('/api/groups', groups); 

// catch 404 and forward to error handler 
app.use(function(req, res, next) { 
    var err = new Error('Not Found'); 
    err.status = 404; 
    next(err); 
}); 

// error handlers 

// development error handler 
// will print stacktrace 
if (app.get('env') === 'development') { 
    app.use(function(err, req, res, next) { 
    res.status(err.status || 500); 
    res.render('error', { 
     message: err.message, 
     error: err 
    }); 
    }); 
} 

// production error handler 
// no stacktraces leaked to user 
app.use(function(err, req, res, next) { 
    res.status(err.status || 500); 
    res.render('error', { 
    message: err.message, 
    error: {} 
    }); 
}); 


module.exports = app; 

index.js

var express = require('express'); 
var router = express.Router(); 
var graph = require('fbgraph'); 
var User = require('../models/user'); 
var jwt = require('jsonwebtoken'); 
var bodyParser = require('body-parser'); 
var AWS = require('aws-sdk'); 
var request = require('request'); 
var uploader = require('../upload'); 
var config = require('../config'); 
var mongoose = require('mongoose'); 



/* GET home page. */ 
router.get('/', function(req, res, next) { 
    res.render('API', { title: 'Welcome to the api' }); 
}); 

module.exports = router; 

回答

1

安裝玉

npm install jade 

確保有意見/ API.jade,如果您渲染此頁......請出示控制器代碼在您的控制器要渲染API.JADE res.render

「 API」,..

創建一個文件夾視圖.. API.jade

**API.jade** 


extends layout 
block content 
h1= title 
p Welcome to #{title} 
+0

現在,我接着說:VAR玉=需要( '玉');',它是媒體鏈接安裝'npm install jad e --save'沒有變化 –

+0

你已經安裝了這個應用程序從快遞發電機...請檢查是否有jade目錄裏面node_modules ... –

+0

是的,我使用了快遞發電機,然後我刪除玉來嘗試'帕格',然後重新安裝玉它給出了這個錯誤 –

相關問題