0

布局.jade

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

索引.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)

请帮忙。

4

1 回答 1

1

两个问题:

  1. extends不是extend

  2. 您的块需要与扩展处于同一“级别”

这将起作用:

extends layout   

block content
  h2 blah blah blah

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

于 2020-04-14T14:30:15.227 回答