此问题之前曾被问过几次,但我似乎无法根据其他答案解决这个问题。所以无论我做什么,我似乎都会继续Failed to lookup view "API" in views directory "/Users/MYUSER/Desktop/matchmaking/app/views"
。即使路径似乎正确吗?
文件结构
├───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;
答案 0 :(得分:1)
安装玉器
npm install jade
确保有视图/ API.jade,如果您正在渲染此页面...请显示控制器代码
在您的控制器中,您正在渲染API.JADE res.render(“API”,..
在views文件夹中创建一个文件.. API.jade
**API.jade**
extends layout
block content
h1= title
p Welcome to #{title}