【问题标题】:Jade in Express JS is not RenderingExpress JS 中的 Jade 未呈现
【发布时间】:2017-07-12 14:10:47
【问题描述】:

我正在使用 input(name="name") 排除来自 from 的用户名。

我已经用 console.log(res.body.name) 检查了这个名字。甚至 res.send("message") 都在工作,但玉不工作。

我的 index.js

var express = require('express');
var app = express();
var router = express.Router();

router.post('/', function(req, res){
    var user = req.body.name; 
    if(user) {
            console.log('User Exist');
            res.render('show_message', {message: "User exist", type: "UserExist"});
        }
    else {
            console.log('User is New');
            res.render('show_message', {message: "User Doesn't exist", type: "NoUserExist"});
      }

}

module.exports = router;

show_message.jade

html
head
    title Person
body
    if(type=="LoginSuccess")
        h3(style="color:green") #{message}

    if(type=="error")
        h3(style="color:red") #{message}

    if(type == "success")
        h3 New person, name: #{person.name}, Registered

    if(type == "NoUserExist")
        h3(style="color:red") #{Message}

    if(type == "UserExist")
            h3(style="color:red") #{Message}

玉不渲染。一个空白网页来了。

【问题讨论】:

    标签: javascript node.js express pug


    【解决方案1】:

    变量区分大小写 - {message} 而不是 {Message}:

    if(type == "NoUserExist")
        h3(style="color:red") #{message}
    
    if(type == "UserExist")
            h3(style="color:red") #{message}
    

    【讨论】:

    • 感谢 Stdob。这真的很有帮助。
    猜你喜欢
    • 2015-08-06
    • 1970-01-01
    • 2016-05-30
    • 2012-06-20
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 2013-07-01
    • 1970-01-01
    相关资源
    最近更新 更多