Jade不会渲染视图。 如果我将new.jade文件的内容更改为段落,则呈现正常。所以我不明白发生了什么。 如果我查看控制台有500错误
提前致谢
以下是一些更多细节
new.jade文件
h1 Log in
form(method="POST", action="/session")
p
label(for="username") Username<br />
input#username(name="username")
p
label(for="password") Name<br />
input#name(name="name")
p
label(for="password") Password<br />
input#password(type="password", name="password")
p
label(for="bio") Bio<br />
textarea#bio(name="bio")
p
input(type="submit", value="Create");
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 session = require('express-session');
var routes = require('./routes/index');
var users = require('./routes/users');
var sessions = require('./routes/session')
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser('my secret string'));
app.use(session({
secret: 'my secret string',
maxAge: 3600000,
saveUninitialized: true,
resave: true
}));
app.use(function(req, res, next) {
res.locals.session = req.session;
next();
});
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', routes);
app.use('/users', users);
app.use('/session', sessions);
// 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;
最后调用它的session.js
var express = require('express')
var session = require('express-session')
var router = express.Router();
var users = require('../data/users');
var app = express();
router.get('/new', function(req, res) {
res.render('session/new', {title: "Log in"});
//res.send("testing");
});
router.get('/', function(req, res) {
res.send("test")
})
router.post('/', function(req, res) {
if (users[req.body.username] &&
users[req.body.username].password === req.body.password) {
req.session.user = users[req.body.username];
res.redirect('users');
} else {
res.redirect('session/new')
}
});
router.delete('/', function(req, res) {
req.session.destroy();
res.redirect('users');
});
module.exports = router;
我只是感到困惑
答案 0 :(得分:1)
您必须删除jade文件末尾的;
。