我使用Node,express和jade模板创建了登录表单。但我的登录页面不使用默认布局。这是我的网站结构:
我的layout.jade:
!!!
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
#header
h1=title
!= body
我的路线.js:
var routes = function(app) {
app.get('/login', function(req, res) {
return res.render(__dirname+"/views/login", {
title: 'Giriş',
stylesheet: 'login'
});
});
};
module.exports = routes;
我的login.jade:
form(action= '/sessions', method='post')
label
| Kullanıcı Adı:
input(type='text', name='user')
label
| Şifre:
input(type='password', name='password')
input(type='submit', name='Giriş')
我的server.js(app.js):
/**
* Module dependencies.
*/
var express = require('express');
var http = require('http');
var path = require('path');
var app = express();
// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) {
app.use(express.errorHandler());
}
//Routes
require('./apps/authentication/routes')(app)
http.createServer(app).listen(app.get('port'), function(){
console.log('Express server listening on port ' + app.get('port'));
});
当我尝试http://www.mylocalhost:3000/login时,它没有异常,但没有使用我的layout.jade。有什么想法吗?
答案 0 :(得分:1)
问题解决了。 将此代码添加到login.jade
extends ../../../views/layout
block login
此代码为layout.jade
block login