Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
499 views
in Technique[技术] by (71.8m points)

Nunjucks模板引擎中子模板继承父模板,请求不到css和js

父模板


    <!doctype html>
    <html lang="zh-CN">
        <meta charset="UTF-8">
        <meta name="viewport"
              content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        {% block stylesheets %}
            <link rel="stylesheet" href="../css/sytle.css">
        {% endblock %}
        {#{% block title %}
            测试继承
        {% endblock %}#}
    </head>
    <body>
        {% block body %}
        {% endblock %}
        {% block script %}
        {% endblock %}
    </body>
    </html>

子模板:


    {% extends './layouts/layou.nunjs' %}
    {% block title %}
        <title>首页</title>
        <link rel="stylesheet" href="../css/style.css">
    {% endblock %}
    {% block body %}
        <div class="head">
            {% include './layouts/head.nunjs' %}
        </div>
        {% for ingredient, amount in food %}
            <p>Use {{ amount }} of {{ ingredient }}</p>
        {% endfor %}
    {% endblock %}

在访问子模板时,继承的父模板中请求的css和js并不能成功请求到。Chrome中提示的是:
Faild to load response data。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

是我自己傻逼了,没理解node设置静态资源目录的概念。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...