如何解决在Google App Engine Python中提供静态html
| 我无法为Python加载静态.html
页面
应用程式。当我单击类似index.html的链接时,出现空白页,并且在服务器上记录404错误。其他静态“ 0”文件(例如about.html)也是如此。
该应用程序可以阻止静态文件。我试着看
很多地方,但我似乎无法使.html页面最多。即
INFO 2011-04-16 17:26:33,655 dev_appserver.py:3317] \“获取/
terms.html HTTP / 1.1 \“ 404-
yaml:
application: quote
version: 1
runtime: python
api_version: 1
handlers:
- url: /index\\.html
script: index.py
- url: /
script: index.py
- url: /(.*\\.(html))
static_files: static/\\1
upload: static/HTML/(.*\\.(html))
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: images/favicon.ico
mime_type: image/x-icon
- url: /css
static_dir: static/css
- url: /images
static_dir: static/images
- url: /js
static_dir: static/js
我的静态文件位于static / HTML中,而index.html位于主文件夹中。
我也尝试过此方法,但似乎完全没有区别:
- url: /favicon.ico
static_files: static/images/favicon.ico
upload: images/favicon.ico
mime_type: image/x-icon
- url: /css
static_dir: static/css
- url: /images
static_dir: static/images
- url: /js
static_dir: static/js
- url: /(.*\\.(html))
static_files: static/\\1
upload: static/HTML/(.*\\.(html))
- url: /index\\.html
script: index.py
- url: /
script: index.py
解决方法
将您的HandlerScript保持在“静态目录”处理部分的下面。 IOW,将其移至最后。
- url: /index\\.html
script: index.py
- url: /
script: index.py
,在您的static_files路径中放入ѭ5:
- url: /(.*\\.(html))
static_files: static/HTML/\\1
upload: static/HTML/(.*\\.(html))
,您不必在yaml文件中单独定义每个目录
handlers:
- url: /static
static_dir: my_application/static
然后在将要用django渲染的相关html文件中,您可以调用静态内容,例如
<script src=\"/static/less_lib.min.js\"></script>
,您必须正确缩进您的YAML。
提供
脚本级别不正确
handlers:
- url: /index\\.html
script: index.py
相当于json
{
\"handlers\": [
{
\"url\": \"/index\\\\.html\"
}
],\"script\": \"index.py\"
}
缩进
正确级别的脚本
handlers:
- url: /index\\.html
script: index.py
相当于json
{
\"handlers\": [
{
\"url\": \"/index\\\\.html\",\"script\": \"index.py\"
}
]
}
在线YAML解析器
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。