【发布时间】:2017-08-15 07:03:29
【问题描述】:
我意识到这个问题已经被问过几次,但似乎没有一个解决方案有帮助。
我正在尝试使用 Flask 为我的网站提供一些基本的 HTML 和 CSS。 在 App Engine 上,Flask 正确地提供模板,但无法在 static/css 文件夹中找到样式表(我在开发者控制台的日志中收到 404)。
我的项目的相关结构是这样的:
/app
/static
/css
style.css
/templates
home.html
我使用的命令是:
render_template('home.html')
在主python文件中,
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}">
在html中链接样式表。 我的 app.yaml 文件非常基础:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: main.app
- url: /static
static_dir: static
expiration: "7d"
现在,当我在 localhost 上运行它时,它可以正常工作,并且 url_for 函数可以正确获取样式表,但在 Google Cloud Platform 上却没有,尽管在“开发”选项卡中获取了正确的文件路径并具有正确的源代码,只有提供 HTML。 如果有帮助,这是我用来部署应用程序的命令:
gcloud app deploy app.yaml --project my-project
我确定问题就在我面前,但我想不通。任何见解将不胜感激。提前谢谢你。
【问题讨论】:
标签: python google-app-engine flask google-cloud-platform google-app-engine-python