![](/img/trans.png)
[英]How to add a value from html file with jinja2 into python array
[英]GAE python Jinja2 multiple html same css file but only one html is rendered correctly
我嘗試使用Google App Engine,Python和Jinja2建立一個小型博客。 我有3個不同的HTML文件,它們引用相同的CSS文件:
<link href="css/index.css" rel="stylesheet" type="text/css">
我的app.yaml具有以下聲明:
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /css
static_dir: templates/css
- url: .*
script: main.app
libraries:
- name: webapp2
version: "2.5.2"
- name: jinja2
version: latest
我的問題是只有我的html文件可以正確呈現! 它們位於同一文件夾中,即“模板”。 有什么指示為什么會發生這種情況? 謝謝
GAE有點不同,您必須明確告訴它您希望它提供靜態文件:css,圖像。 等等。https://developers.google.com/appengine/docs/python/gettingstartedpython27/staticfiles
首先,您的app.yaml中的處理程序應如下所示:
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: /stylesheets
static_dir: stylesheets
/ stylesheets將包含您的CSS。 現在,GAE將看到您要在your-app / stlyesheets路徑中提供所有文件。
在這種情況下,您的文件結構將如下所示:
your-app
--main.py
--app.yaml
--stylesheets
--style.css
--templates
--front.html
現在已經為CSS提供了服務,您只需在HTML中引用它即可
<link href="/stylesheets/style.css" rel="stylesheet" type="text/css" />
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.