Pug - 无法通过样板的第 1 步

发布于 2025-01-17 07:46:42 字数 465 浏览 1 评论 0原文

完全是菜鸟问题,但我找不到任何解决方案,抱歉,所以最后的办法是在这里提问。

我正在努力学习哈巴狗。已创建样板项目,无法呈现索引页。我已经尽可能多地搜索和阅读,但我得到的只是“解析 with 表达式的正文时出错”错误。 index.js 看起来很简单,如下所示,但让我停了下来:

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

// GET home page. 
router.get('/', (req, res) => {
  res.render('index', { title: 'Express' });
});

module.exports = router;

如果有人可以提供一条线路来为我指明正确的方向来解决这个问题,并继续我的哈巴狗和 Nodejs 之旅,我将非常感激。哈巴狗在这个阶段显得非常困难,尽管大家都对它赞不绝口:/

total noob question but I cannot find any solutions to this sorry so last resort is to ask here.

I am trying to learn pug. Have created a boilerplate project and unable to render index page. Ive searched and read as much as I can but all I get is 'Error parsing body of the with expression' error. The index.js looks as simple as follows but stopping me in my tracks:

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

// GET home page. 
router.get('/', (req, res) => {
  res.render('index', { title: 'Express' });
});

module.exports = router;

if anyone can provide a one liner to point me in the right direction to resolve this and keep rolling on my pug and nodejs journey I'd really appreciate it. Pug is appearing very difficult at this stage despite all the raving about it :/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

恍梦境° 2025-01-24 07:46:42

我检查了我的一个旧项目。您可以尝试这样的操作:

安装 pug:

$ npm install pug --save

然后设置应用程序:

const express = require('express')
const app = express()
const port = 3000

// you don’t have to specify the engine or load the template engine module in your app; 
// Express loads the module internally, as shown below (for the above example).

app.set('view engine', 'pug')

// views, the directory where the template files are located
// This defaults to the views directory in the application root directory.

app.set('views', './views')


app.get('/', (req, res) => {
  res.render('index', { title: 'Hey', message: 'Hello there!' })
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

示例 pug 文件:

html
  head
    title= title
  body
    h1= message

使用模板引擎

I have checked one of my old projects. You can try something like this:

Install pug:

$ npm install pug --save

Then set up the app:

const express = require('express')
const app = express()
const port = 3000

// you don’t have to specify the engine or load the template engine module in your app; 
// Express loads the module internally, as shown below (for the above example).

app.set('view engine', 'pug')

// views, the directory where the template files are located
// This defaults to the views directory in the application root directory.

app.set('views', './views')


app.get('/', (req, res) => {
  res.render('index', { title: 'Hey', message: 'Hello there!' })
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

Example pug file:

html
  head
    title= title
  body
    h1= message

Using template engines

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文