我无法使用 block 和 exports 访问 pug 文件

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

这个问题需要一整天才能解决,但仍然没有发生帮助我。我只是想使用块和导出方法访问 pug 文件。这是代码,

------服务于代码的.js代码(aaryae.js)

const http = require('http');
const path = require('path');
const express = require('express');
const pug = require('pug');
const port = 80;
const app = express();
app.use('/static', express.static('static'));
app.use(express.urlencoded());
app.set('view engine', 'pug');
app.set('views', path.join(__dirname, 'views'));
app.get('/', (req, res) => {
    res.status(200).render('base.pug');
})
 app.listen(port, () => {
    console.log(`running on the port ${port}`);
})

------ 作为 (base.pug) 的主要 pug 文件

doctype html
html(lang="en")
    head
        title aaryae
        block style
    body 
        block content 
            
        block scripts

----子 pug 文件为 ( home.pug )

extends base.pug

block style 
    style `your text`
        include ../static/style.css

block content 
    h1 The aaryae is the most talent human in this entire planet and i feel so proud of it .  

-----style.css

*{
    background: black;
    color: white;
    font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
    
}

注意:我有一个名为 pratise 的文件夹,其中包括 (aaryae.js) 和其他两个文件夹 (views):包含 base.pug 和 home.pug 以及(静态):包含 style.css

我只是希望访问 home.pug 我尝试了扩展和导出,但它没有用,当我检查视图源时,我发现标题为 aaryae,但我认为它没有访问块部分

javascript node.js pug hosting
© www.soinside.com 2019 - 2024. All rights reserved.