Jinja没有在子目录中渲染css /图像 [英] Jinja not rendering css/images in sub-directories

查看:78
本文介绍了Jinja没有在子目录中渲染css /图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Jinja2和GAE,并且使用辅助函数来呈现HTML文件。当我尝试渲染嵌套在子目录(游戏化)中的HTML文件时,Jinja似乎没有拉出CSS和图像文件。有谁知道我该怎么办?

I'm using Jinja2 and GAE, and I'm using a helper function to render HTML files. When I try to render a HTML file that is nested within a subdirectory (Gamification), Jinja doesn't seem to be pulling out the CSS and images files. Does anyone know what I should do?

我目前的YAML结构如下

My current YAML structure is as follows

handlers:
- url: /favicon\.ico
  static_files: favicon.ico
  upload: favicon\.ico

- url: .*
  script: main.app

libraries:
- name: webapp2
  version: "2.5.1"
- name: jinja2
  version: latest

我目前的目录结构就是这样。

My current directory structure is as such.

Main directory
|
 -- main.py

|
 ----Templates
     |
      --Gamification
        |
         --index.html
           |
            --CSS
              |
               --1.css
           |
            --img
              |
               --1.jpef

main.py

main.py

jinja_environment = jinja2.Environment(loader=jinja2.FileSystemLoader(['Templates', 'Templates\Gamification']));
def import_html(self, address, val = {}):
    template = jinja_environment.get_template(address);
    self.write(template.render(val));

有问题的html文件如下:

The html file in question is as follows:

<!DOCTYPE html>
<html>
  <head>
    <title>Gamification</title>
    <link href="css/bootstrap.css" rel="stylesheet">
  </head>

  <body>

<img src = "img/dan.jpeg" class = "img-rounded" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="js/bootstrap.js"></script>
</body>
</html>


推荐答案

看起来你没有声明静态目录img和css。

类似于:

It looks like you didn't declare static directories for the img and css.
something like:

- url: /css
  static_dir: css

这篇关于Jinja没有在子目录中渲染css /图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆