使用expressJS时使用jade时出错

时间:2014-01-14 19:30:23

标签: node.js express pug

我收到来自下面复制的一个jade文件的错误消息(错误:找到字符串的末尾但未找到右括号) - 我已将下面使用的两个玉文件复制为好。

Login.jade

extends layout

    block content
       .login.well
          h1  Please login in...
          hr
          form(id='login', method='POST', action='/login' novalidate)
               .form-group
                  label(for='username') Username
                  input(type='text', name='username', class='form-control', id='username' placeholder='Enter usernamea', required, data-required-msg='Username is required')
               .form-group
                  label(for='password') Password
                  input(type='password', name='password', class='form-control', id='password', placeholder='Enter password', required, data-required-msg='Password is required')
               .form-group
                   button.btn.btn-default Login
               include messages

messages.jade

if flash
   p flash
   div.alert(class='#{flash.type}')
     ul
     - for (var i = 0; i< flash.messages.length; i++) {
         li #{flash.messages[i]/msg}
     - }
     ul

layout.jade

doctype html
html
  head
    title= title
    link(rel='stylesheet', href='//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css')
    link(rel='stylesheet', href='/stylesheets/style.css')
    a: img(src="/images/logo.png", alt="Test Test")
  body
    block content

    script(src='//code.jquery.com/jquery-1.10.1.min.js')

错误讯息:

500 Error: /home/devName/devCompany/node-v0.10.22/dashboard/views/login.jade:18<br/> 16| include messages<br/> 17| <br/> > 18| <br/><br/>The end of the string was reached with no closing bracket found.

    16| include messages
    17|
    > 18|
    The end of the string was reached with no closing bracket found.
    at parseMax (/home/devName/devCompany/node-v0.10.22/node_modules/jade/node_modules/character-parser/index.js:26:13)
    at Object.Compiler.buffer (/home/devName/devCompany/node-v0.10.22/node_modules/jade/lib/compiler.js:96:25)
    at Object.Compiler.visitText (/home/devName/devCompany/node-v0.10.22/node_modules/jade/lib/compiler.js:485:10)
    at Object.Compiler.visitNode (/home/devName/devCompany/node-v0.10.22/node_modules/jade/lib/compiler.js:210:37)
    at Object.Compiler.visit (/home/devName/devCompany/node-v0.10.22/node_modules/jade/lib/compiler.js:197:10)
    at Object.Compiler.visitBlock (/home/devName/devCompany/node-v0.10.22/node_modules/jade/lib/compiler.js:278:12)
    at Object.Compiler.visitNode (/home/devName/devCompany/node-v0.10.22/node_modules/jade/lib/compiler.js:210:37)
    at Object.Compiler.visit (/home/devName/devCompany/node-v0.10.22/node_modules/jade/lib/compiler.js:197:10)
    at Object.Compiler.visitTag (/home/devName/devCompany/node-v0.10.22/node_modules/jade/lib/compiler.js:445:12)
    at Object.Compiler.visitNode (/home/devName/devCompany/node-v0.10.22/node_modules/jade/lib/compiler.js:210:37)

2 个答案:

答案 0 :(得分:1)

尝试从ul文件中删除第二个messages.jade

if flash
   p flash
   div.alert(class='#{flash.type}')
     ul
     - for (var i = 0; i< flash.messages.length; i++) {
         li #{flash.messages[i]/msg}
     - }

答案 1 :(得分:0)

我的messages.jade文件中有一个类型。我在倒数第二行有一个斜线而不是一个点,它产生了错误(不太有用):

if flash
   p flash
   div.alert(class='#{flash.type}')
     ul
     - for (var i = 0; i< flash.messages.length; i++) {
         li #{flash.messages[i].msg}
     - }