Serving static html in Google app engine Python

断了今生、忘了曾经 提交于 2019-11-27 18:33:40

问题


I'm having trouble getting static .html pages loaded for my Python app. When I click on a link like index.html, I get a blank page and on the server log a 404 error. This is the same for other static .html files such as 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. i.e.

INFO 2011-04-16 17:26:33,655 dev_appserver.py:3317] "GET / 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

My static files are located in static/HTML and index.html is in the main folder.

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

回答1:


Keep your HandlerScripts below the Static Directory handling portion. IOW, just move this to the last.

- url: /index\.html
script: index.py

- url: /
script: index.py



回答2:


Put an /HTML in your static_files path:

- url: /(.*\.(html))
  static_files: static/HTML/\1
  upload: static/HTML/(.*\.(html))



回答3:


You don't have to define each directory seperatly in you yaml file

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

<script src="/static/less_lib.min.js"></script>



回答4:


You must properly indent your YAML.

Provided

script at incorrect level

handlers:
- url: /index\.html
script: index.py

json equivalent

{
  "handlers": [
    {
      "url": "/index\\.html"
    }
  ], 
  "script": "index.py"
}

Indented

script at correct level

handlers:
- url: /index\.html
  script: index.py

json equivalent

{
  "handlers": [
    {
      "url": "/index\\.html", 
      "script": "index.py"
    }
  ]
}

Online YAML Parser



来源:https://stackoverflow.com/questions/5693976/serving-static-html-in-google-app-engine-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!