我意识到这已被问过几次,但没有一个解决方案似乎有所帮助.
我正在尝试使用Flask为我的网站提供一些基本的HTML和CSS.在App Engine上,Flask正确地提供模板,但是无法在static/css文件夹中找到样式表(我在开发人员控制台的日志中获得404s).
我的项目的相关结构是这样的:
/app
/static
/css
style.css
/templates
home.html
Run Code Online (Sandbox Code Playgroud)
我正在使用的命令是:
render_template('home.html')
Run Code Online (Sandbox Code Playgroud)
在主python文件中,
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/style.css') }}">
Run Code Online (Sandbox Code Playgroud)
在html中链接样式表.我的app.yaml文件非常基本:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: main.app
- url: /static
static_dir: static
expiration: "7d"
Run Code Online (Sandbox Code Playgroud)
现在,当我在localhost上运行它时,这种方法正常,并且url_for函数正确地获取样式表,但在Google Cloud Platform上没有,尽管获得了正确的文件路径并且在"开发"选项卡中有正确的源代码,但只提供了HTML .如果有帮助,这是我用来部署应用程序的命令:
gcloud app deploy app.yaml --project my-project
Run Code Online (Sandbox Code Playgroud)
我确定问题就在我面前,但我无法弄明白.任何见解将不胜感激.先感谢您.
python google-app-engine flask google-cloud-platform google-app-engine-python