0
おはようございます、私は現在ノードを学び、小さなプロジェクトを作成しています。私は問題を抱えています。私は解決できないようです。私はルートを含む明白なバックエンドを持っていますが、これらのルートは郵便配達員でうまく動作しますが、pugテンプレートを使用して組み込むと、フォームの詳細が通過しないようです。 これは、pugテンプレートがフォームから属性を収集していない場合と同じですが、検証エラー '氏名などが必要です'を送信します。これはPUGを使った初めてのことなので、どんな助け(あるいは愚かさへのポインタ)も大変感謝しています。ルートのノードエクスプレスのPugテンプレート - POSTに関する問題
:
//Register new user
router.post('/register', function(req,res,next){
user.create(req.body).then(function(user){
res.send(user); //new instance and save
}).catch(next);
});
PUGテンプレートの場合:
extends layout
block content
h1 Sign Up
form#addUser(name="adduser",action='api/register', method='POST')
label(for='firstName') First Name
input#users.firstName(type='text' placeholder='firstName' name='firstName')
div.form-group
label(for='lastName') Last Name
input#users.lastName(type='text' placeholder='lastName' name='lastName')
div.form-group
label(for='userName') UserName
input#users.userName(type='text' placeholder='userName' name='userName')
div.form-group
label(for='password') Password
input#users.password(type='password' placeholder='password' name='password')
div.form-group
label(for='email') Email
input#users.email(type='text' placeholder='email' name='email')
div.form-group
label(for='jobTitle') Job Title
input#users.jobTitle(type='text' placeholder='jobTitle' name='jobTitle')
button(type='submit', value='add') SignUp
ユーザーモデル:
const UserSchema = new Schema({
userName: {
type: String,
unique: true,
required:[true, "Username is required"]
},
password: {
type: String,
required: [true, "Password is required"]
},
email: {
type: String,
required: [true, "Email is required"]
},
firstName: {
type: String,
required:[true, "Name field is required"]
},
lastName: {
type: String,
required: [true, "Name field is required"]
},
jobTitle :{
type: String,
required: [true, "Position is required"]
}
});
const User = mongoose.model('users', UserSchema);
module.exports = User;
エラー出力:
ユーザ名は必須です。ユーザ名は必須です。ユーザ名は必須です。ユーザ名は必須です。ユーザ名は必須です。