簡體   English   中英

在Google應用引擎Python中提供靜態HTML

[英]Serving static html in Google app engine Python

我在為我的Python應用程序加載靜態.html頁面時遇到了麻煩。 當我點擊像index.html這樣的鏈接時,我得到一個空白頁面,並在服務器上記錄404錯誤。 對於其他靜態.html文件(例如about.html)也是如此

該應用程序可以阻止靜態文件。 我曾嘗試在很多地方尋找,但我似乎無法獲得.html頁面。

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

我的靜態文件位於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

將HandlerScripts保留在靜態目錄處理部分下方。 IOW,把它移到最后。

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

- url: /
script: index.py

/HTML static_files路徑中放置一個/HTML

- 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 Parser

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM