错误:无法在视图目录节点 JS 和 Jquery 错误中查找视图“错误”
Posted
技术标签:
【中文标题】错误:无法在视图目录节点 JS 和 Jquery 错误中查找视图“错误”【英文标题】:Error: Failed to lookup view "error" in views directory Node JS and Jquery Error 【发布时间】:2017-12-07 06:08:54 【问题描述】:即使查看了以前的帖子,我也无法弄清楚这个问题的解决方案。
我收到以下错误:
GET /public/stylesheets/nice-select.css 404 2.429 毫秒 - 1594 错误:无法在视图目录“/home/nmysore/phpstormProjects/Makerspace/express_example/views”中查找视图“错误” 在 EventEmitter.render (/home/nmysore/PhpstormProjects/Makerspace/express_example/node_modules/express/lib/application.js:580:17) 在 ServerResponse.render (/home/nmysore/PhpstormProjects/Makerspace/express_example/node_modules/express/lib/response.js:971:7) 在/home/nmysore/PhpstormProjects/Makerspace/express_example/app.js:49:7 在 Layer.handle_error (/home/nmysore/PhpstormProjects/Makerspace/express_example/node_modules/express/lib/router/layer.js:71:5) 在 trim_prefix (/home/nmysore/PhpstormProjects/Makerspace/express_example/node_modules/express/lib/router/index.js:315:13) 在/home/nmysore/PhpstormProjects/Makerspace/express_example/node_modules/express/lib/router/index.js:284:7 在 Function.process_params (/home/nmysore/PhpstormProjects/Makerspace/express_example/node_modules/express/lib/router/index.js:335:12) 在下一个(/home/nmysore/PhpstormProjects/Makerspace/express_example/node_modules/express/lib/router/index.js:275:10) 在/home/nmysore/PhpstormProjects/Makerspace/express_example/app.js:38:3 在 Layer.handle [as handle_request] (/home/nmysore/PhpstormProjects/Makerspace/express_example/node_modules/express/lib/router/layer.js:95:5)
我正在尝试使用一些 jQuery 包在选择元素和使用 node.js 服务器时获得漂亮的动画。
http://hernansartorio.com/jQuery-nice-select/
我目前的结构是:
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 stylus = require('stylus');
var index = require('./routes/index');
var users = require('./routes/users');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
// unce(bodyParser.json());
app.use(bodyParser.urlencoded( extended: false ));
app.use(cookieParser());
app.use(stylus.middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
app.use('/users', users);
app.engine('html', require('ejs').renderFile);
// 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 handler
app.use(function(err, req, res, next)
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : ;
// render the error page
res.status(err.status || 500);
res.render('error');
);
module.exports = app;
在我的 index.html 中:
<!DOCTYPE html>
<html>
<script src="public/javascripts/jquery.js"></script>
<script src="public/javascripts/jquery.nice-select.js"></script>
<link rel = "stylesheet" href="public/stylesheets/nice-select.css">
<script>
$(document).ready(function()
$('select').niceSelect();
);
</script>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
<select name='Major'>
<option disabled selected>Select Major</option>
<option value="1">All Majors</option>
<option value="2">Computer Science</option>
<option value="3">Structural Engineering</option>
<option value="4">Cognitive Science</option>
<option value="5">Bioengineering</option>
<option value="6">Electrical Engineering</option>
<option value="7">Etc</option>
<option value="8">Etc</option>
</select>
</body>
</html>
我在以前的线程上尝试了一堆建议,但错误并没有消失。
【问题讨论】:
【参考方案1】:您正在使用此行请求 error.html
视图:
res.render('error');
但它在views
文件夹中不存在。添加一个error.html
,它应该会呈现。
【讨论】:
以上是关于错误:无法在视图目录节点 JS 和 Jquery 错误中查找视图“错误”的主要内容,如果未能解决你的问题,请参考以下文章
节点无法在 Express/react 应用程序中查找视图“错误”
Nodejs / Express:错误:无法在视图目录中查找视图“错误”