运行时出现意外的令牌“缩进”错误

问题描述 投票:0回答:1

layout.jade

doctype
html
    head
      title=title
      link(rel='stylesheet',href='/stylesheet/style.css')
    body
      block content 

index.jade

extend layout   

  block content 
      h1 Add new contact
      form(method="POST", action='/new_contact')
      p Name:
      input#title(type="text ",name=name)
      p Phone:
      input#title(type="text",name=phone)

      p: button(type="submit") Add new Contact
      h1 Add new database
      form(method="POST", action='/createdb')
      p Database name:
      input#title(type="text",name=dbname)
      p: button(type="submit") Add new Database

      h1 Delete the Contact
      form(method="POST", action='/delete_contact')
      p Phone:
      input#title(type="text",name=phone)
      p: button(type="submit") Delete Contact

      h1 View the Contact
      form(method="POST", action='/view_contact')
      p Phone:
      input#title(type="text",name=phone)
      p: button(type="submit") View the  Contact

我在运行应用程序时不断收到此错误

Error: C:\Users\Priyanka-PC\Desktop\Node\NodeApp\views\index.jade:3
    1|       extend layout
    2|       
  > 3|         block content 
    4|             h1 Add new contact
    5|             form(method="POST", action='/new_contact')
    6|             p Name:

unexpected token "indent"
    at Parser.parseExpr (C:\Users\Priyanka-PC\Desktop\Node\NodeApp\node_modules\jade\lib\parser.js:254:15)
    at Parser.parse (C:\Users\Priyanka-PC\Desktop\Node\NodeApp\node_modules\jade\lib\parser.js:122:25)
    at parse (C:\Users\Priyanka-PC\Desktop\Node\NodeApp\node_modules\jade\lib\index.js:104:21)
    at Object.exports.compile (C:\Users\Priyanka-PC\Desktop\Node\NodeApp\node_modules\jade\lib\index.js:205:16)
    at handleTemplateCache (C:\Users\Priyanka-PC\Desktop\Node\NodeApp\node_modules\jade\lib\index.js:174:25)
    at Object.exports.renderFile (C:\Users\Priyanka-PC\Desktop\Node\NodeApp\node_modules\jade\lib\index.js:380:10)
    at Object.exports.renderFile (C:\Users\Priyanka-PC\Desktop\Node\NodeApp\node_modules\jade\lib\index.js:370:21)
    at View.exports.__express [as engine] (C:\Users\Priyanka-PC\Desktop\Node\NodeApp\node_modules\jade\lib\index.js:417:11)
    at View.render (C:\Users\Priyanka-PC\Desktop\Node\NodeApp\node_modules\express\lib\view.js:135:8)
    at tryRender (C:\Users\Priyanka-PC\Desktop\Node\NodeApp\node_modules\express\lib\application.js:640:10)

请帮助。

couchdb pug node-modules unexpected-token
1个回答
1
投票

两个问题:

  1. extends而不是extend

  2. 您的代码块必须与扩展代码处于同一“级别”

这将起作用:

extends layout   

block content
  h2 blah blah blah

请阅读pug中有关继承的docs,以获取更多详细信息和一些示例。

© www.soinside.com 2019 - 2024. All rights reserved.