我正在使用mongoose和express进行节点js CRUD操作,这需要我在运行应用程序时显示数据库中某个人的详细信息,我收到以下错误。
ReferenceError:C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ views \ show.ejs:5 3 |
4| <div>
5 | &lt;%=讲师。指定%&gt;
6| <div><%= lecturers.lect_id %></div>
7| <div><%= lecturers.full_name %></div>
8| <div><%= lecturers.gender %></div>
讲师没有定义
在eval(eval at compile(C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ ejs \ lib \ ejs.js:549:12),:22:26)
at returnedFn(C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ ejs \ lib \ ejs.js:580:17)
在tryHandleCache(C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ ejs \ lib \ ejs.js:223:34)
在View.exports.renderFile [作为引擎](C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ ejs \ lib \ ejs.js:437:10)
在View.render(C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ express \ lib \ view.js:135:8)
在tryRender(C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ express \ lib \ application.js:640:10)
在Function.render(C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ express \ lib \ application.js:592:3)
在ServerResponse.render(C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ express \ lib \ response.js:1008:7)
在C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ app.js:63:8
在C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ mongoose \ lib \ model.js:3930:16
在_init(C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ mongoose \ lib \ query.js:2007:5)
在model.Document.init(C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ mongoose \ lib \ document.js:370:5)
at completeOne(C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ mongoose \ lib \ query.js:1993:12)
在立即。 (C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ mongoose \ lib \ query.js:1520:11)
在立即。 (C:\ Users \ Mussa \ Desktop \ TimeTable \ v2 - Copy \ node_modules \ mquery \ lib \ utils.js:119:16)
在runCallback(timers.js:789:20)
这是我在第63行的代码显示错误。
var express = require("express");
var bodyParser = require("body-parser");
var mongoose = require("mongoose");
var secret = require("./config/secret");
var Lecturers = require("./models/lecturers").Lecturer;
var app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended : true}));
app.use(express.static("public"));
app.set("view engine", "ejs");
//Connects to the databse
mongoose.connect(secret.database, function(err){
if(err){
console.log(err);
}else {
console.log("Successfully Connected to the Database");
}
});
//Called direcctly by assigning app
require("./routes/main")(app);
//INDEX
app.get("/lecturers", function(req, res){
Lecturers.find({}, function(err, foundLecturers){
if(err){
console.log(err)
} else {
res.render("index", {lecturers: foundLecturers});
}
});
});
//CREATE
app.get("/lecturers/new", function(req, res){
res.render("new");
});
//CREATE ROUTE
app.post("/lecturers", function(req, res){
Lecturers.create(req.body.lecturer, function(err, lecturers){
if(err){
res.render("new");
}else{
res.redirect("/lecturers");
}
});
});
//SHOW ROUTE
app.get("/lecturers/:id", function(req, res){
Lecturers.findById(req.params.id, function(err, foundLecturer){
if(err){
res.redirect("/lecturers");
console.log(err);
}else{
res.render("show", {lecturer, foundLecturer});
}
});
});
这是我的讲师模型
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
var lecturersSchema = new Schema({
designation: { type: String },
lect_id: { type: String, unique: true, trim: true},
full_name: { type: String},
gender: { type: String}
});
var Lecturer = mongoose.model("Lecturer", lecturersSchema);
module.exports = {Lecturer: Lecturer}
请问我做错了什么?