python - GAE python Jinja2 多个 html 相同的 css 文件,但只有一个 html 被正确呈现

标签 python html css google-app-engine

我尝试使用 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 文件正确呈现!它们位于同一个文件夹中,即“templates”。 关于为什么会发生这种情况的任何指示? 谢谢

最佳答案

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" />

关于python - GAE python Jinja2 多个 html 相同的 css 文件,但只有一个 html 被正确呈现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21792920/

相关文章:

Python 的 urllib2 在某些站点上不起作用

javascript - 如果在 jQuery 中选择了选项,如何显示 div

jquery - 图像上的 div 褪色无法保持显示

python - 如何在Python中优化打印帕斯卡三角形?

python - 包含字符串和数值的数据集中的特征选择?

php - 如何在 mysql 查询中使用 select 选项值作为 from 的来源

css - 我应该将段落视为文本还是文本 block (理论)?

javascript slider 设置超时问题

python - 如何处理 pandas 中互补的重复数据?

javascript - CSS/Javascript 下拉菜单问题