我正在关注 node.js 上的 peepcode(第 1 部分)视频教程,但我被困在前几个步骤上。当我尝试转到时http://localhost:3000/login
,我收到以下错误:
500 错误:无法查找视图“/Users/dantang/Desktop/Programming/Node/basic server/hotpie/apps/authentication/views/login”
我猜这是由于拼写错误,但我已尝试多次更改代码,但我无法弄清楚出了什么问题。如果有人能告诉我我该怎么做,我会非常感激?谢谢!
github 仓库是https://github.com/tangbj/nodejs
服务器.js
/**
* Module dependencies.
*/
require("coffee-script");
var express = require('express')
, http = require('http')
, path = require('path');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
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'));
});
登录.jade
form(action='/sessions', method='post')
label
| Username
input(type='text', name='user')
label
| Password
input(type='password', name='password')
input(type='submit', name='Submit')
路线.咖啡
routes = (app) ->
app.get '/login', (req, res) ->
res.render "#{__dirname}/views/login",
title: 'Login'
stylesheet: 'login'
module.exports = routes
包.json
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"dependencies": {
"express": "3.1.0",
"jade": "*",
"coffee-script": "~1.6.1"
}
}