[英]Serving static html in Google app engine Python
I'm having trouble getting static .html
pages loaded for my Python app. 我在为我的Python应用程序加载静态.html
页面时遇到了麻烦。 When I click on a link like index.html , I get a blank page and on the server log a 404 error. 当我点击像index.html这样的链接时,我得到一个空白页面,并在服务器上记录404错误。 This is the same for other static .html
files such as about.html . 对于其他静态.html
文件(例如about.html)也是如此 。
The application works bar the static files. 该应用程序可以阻止静态文件。 I've tried looking in numerous places, but I cannot seem to get the .html pages up. 我曾尝试在很多地方寻找,但我似乎无法获得.html页面。 ie 即
INFO 2011-04-16 17:26:33,655 dev_appserver.py:3317] "GET / terms.html HTTP/1.1" 404 - INFO 2011-04-16 17:26:33,655 dev_appserver.py:3317]“GET / terms.html HTTP / 1.1”404 -
yaml: 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
My static files are located in static/HTML and index.html is in the main folder. 我的静态文件位于static / HTML中, index.html位于主文件夹中。
I have also tried this, but it seems to make no difference at all: 我也试过这个,但似乎没有任何区别:
- 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
Keep your HandlerScripts below the Static Directory handling portion. 将HandlerScripts保留在静态目录处理部分下方。 IOW, just move this to the last. IOW,把它移到最后。
- url: /index\.html
script: index.py
- url: /
script: index.py
Put an /HTML
in your static_files path: 在/HTML
static_files路径中放置一个/HTML
:
- url: /(.*\.(html))
static_files: static/HTML/\1
upload: static/HTML/(.*\.(html))
You don't have to define each directory seperatly in you yaml file 您不必在yaml文件中单独定义每个目录
handlers:
- url: /static
static_dir: my_application/static
Then in your relevant html file that you will render with django you can call your static content for example like 然后在您将使用django呈现的相关html文件中,您可以调用静态内容,例如
<script src="/static/less_lib.min.js"></script>
You must properly indent your YAML. 你必须正确缩进你的YAML。
Provided 提供
script at incorrect level 脚本不正确
handlers:
- url: /index\.html
script: index.py
json equivalent json相当于
{
"handlers": [
{
"url": "/index\\.html"
}
],
"script": "index.py"
}
Indented 缩进
script at correct level 正确级别的脚本
handlers:
- url: /index\.html
script: index.py
json equivalent json相当于
{
"handlers": [
{
"url": "/index\\.html",
"script": "index.py"
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.