无法查找视图" ..."在views目录" ..."

时间:2015-12-26 15:45:25

标签: node.js pug

今天出现了一个奇怪的错误。我在res.render中遇到错误,但我经常使用它,而且我知道如何使用它。

contact.js:

router.post('/', function (req, res, next) {

    if (!validator.isEmail(req.body.email)) {
        req.flash('error', '...');
        return res.render('contact', {
            message: req.flash()
        })
    }

    contactmessages.create({
        firstname: req.body.firstname,
        lastname: req.body.lastname,
        email: req.body.email,
        message: req.body.message,
        subject: req.body.subject
    }).then(res.render('responseviews/dafaultInfoLayout', {
            user: req.user,
            info: '...'
    })).catch(function (err) {
        res.render('responseviews/noResponseDB');
    });
});

contact.jade:

extends layout

block content
    ul.breadcrumb
        each breadcrumb in breadcrumbs
            li: a(href="#{breadcrumb.url}") #{breadcrumb.name}
    if(message)
        span.label.label-danger #{message.error}
    .container
        .row
            .col-md-12
                form.form-horizontal(method='post').col-md-10
                    fieldset
                        legend.text-center.header Kontaktformular
                        .form-group
                            span.col-md-1.col-md-offset-2.text-center
                                i.fa.fa-user.bigicon
                            .col-md-8
                                if(user)
                                    input#fname.form-control(name='firstname', type='text', value=user.firstname)
                                else
                                    input#fname.form-control(name='firstname', type='text', placeholder='Vorname')
                        .form-group
                            span.col-md-1.col-md-offset-2.text-center
                                i.fa.fa-user.bigicon
                            .col-md-8
                                if(user)
                                    input#lname.form-control(name='lastname', type='text', value=user.lastname)
                                else
                                    input#lname.form-control(name='lastname', type='text', placeholder='Nachname')
                        .form-group
                            span.col-md-1.col-md-offset-2.text-center
                                i.fa.fa-envelope-o.bigicon
                            .col-md-8
                                if(user)
                                    input#email.form-control(name='email', type='text', value=user.email)
                                else
                                    input#email.form-control(name='email', type='text', placeholder='Email Adresse')
                        .form-group
                            span.col-md-1.col-md-offset-2.text-center
                                i.fa.fa-envelope-o.bigicon
                            .col-md-8
                                input#email.form-control(name='subject', type='text', placeholder='Betreff')
                        .form-group
                            span.col-md-1.col-md-offset-2.text-center
                                i.fa.fa-pencil-square-o.bigicon
                            .col-md-8
                                textarea#message.form-control(name='message', placeholder='Schreibe hier, was du ' +
                                'uns mitteilen oder fragen willst', rows='7')
                        .form-group
                            .col-md-12
                                button.btn.btn-primary.btn-lg.col-md-offset-6(type='submit') Absenden

responseviews / defaultInfoLayout.jade:

extends ../layout

block content
    h1 #{info}

我得到的错误:

Error: Failed to lookup view "responseviews/dafaultInfoLayout" in views directory "/home/muecahit/Schreibtisch/ltebjade/lteb/app/views"
    at EventEmitter.render (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/application.js:579:17)
    at ServerResponse.render (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/response.js:961:7)
    at /home/muecahit/Schreibtisch/ltebjade/lteb/app/routes/contact.js:30:14
    at Layer.handle [as handle_request] (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/layer.js:95:5)
    at next (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/route.js:131:13)
    at Route.dispatch (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/layer.js:95:5)
    at /home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/index.js:277:22
    at Function.process_params (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/index.js:330:12)
    at next (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/index.js:271:10)
    at Function.handle (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/index.js:176:3)
    at router (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/index.js:46:12)
    at Layer.handle [as handle_request] (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/index.js:312:13)
    at /home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/index.js:280:7
    at Function.process_params (/home/muecahit/Schreibtisch/ltebjade/lteb/node_modules/express/lib/router/index.js:330:12)

这就是我的文件:

1 个答案:

答案 0 :(得分:0)

错误消息显示“dafaultInfoLayout”,您说“defaultInfoLayout”存在。这不只是你身边的错字/拼写错误吗?

(由于低代表无法评论)

事实上,在阅读完你的代码之后,确实拼错了。

在你的contact.js

then(res.render('responseviews/dafaultInfoLayout'...

需要

then(res.render('responseviews/defaultInfoLayout'...

那应该解决你的问题。