2

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?

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

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));

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>
Shay Erlichmen
  • 31,691
  • 7
  • 68
  • 87
Dan Tang
  • 1,273
  • 2
  • 20
  • 35

2 Answers2

2

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

- url: /css
  static_dir: css
Shay Erlichmen
  • 31,691
  • 7
  • 68
  • 87
  • I had to add "application_readable: true". Otherwise my page would fail to load. Docs: https://cloud.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Static_file_handlers – Dan Carter Dec 02 '14 at 06:17
1

Yes, I had the same problem. You need to do something like this:

- url: /.*/css
  static_dir: templates/css

- url: /.*/js
  static_dir: templates/js

(of course, replace "templates" with whatever subdirectory your css and js folders are located)

fedorqui
  • 275,237
  • 103
  • 548
  • 598
BandfuzzAlex
  • 171
  • 1
  • 1
  • 9