即使查看以前的帖子,我也无法找到解决此问题的方法。
我收到以下错误:
GET /public/stylesheets/nice-select.css 404 2.429 ms - 1594 错误:无法查找视图"错误"在views目录" / 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) at /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) at /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) at /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)
我试图在选择元素和使用node.js服务器时使用一些jQuery包来获得漂亮的动画。
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>
我在以前的主题上尝试过一堆建议,但错误并没有消失。
答案 0 :(得分:1)
您要求使用此行error.html
视图:
res.render('error');
但它并不存在于views
文件夹中。添加error.html
,它应该呈现。