静的ファイルはどうすればいいの?

(例) templates/html/display.html に置いたファイルに http://[host]/html/display.html でアクセスしたい

  • 方法
    • 1.アプリケーションディレクトリにある app.yaml ファイルを開く
    • 2.handlers に設定を追記
 # アドレスで使用する文字列
 - url: /html
   # 静的ファイルを設置するディレクトリ
   static_dir: templates/html
   secure: optional
  • 注意点
    • handlers に記載された設定は、上から順に有効となる。以下のように記載した場合…
 handlers:
 - url: /remote_api
   script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
   secure: optional
   login: admin
 
 - url: /media
   static_dir: _generated_media
   secure: optional
 
 - url: /.*
   script: common/appenginepatch/main.py
   secure: optional
 
 - url: /html
   static_dir: templates/html
   secure: optional

http://[host]/html/display.html でアクセスしても「- url: /.*」が有効となるので「html/display.html」ファイルは呼び出されない。なので以下のように記載すればOK。

 handlers:
 - url: /remote_api
   script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
   secure: optional
   login: admin
 
 - url: /media
   static_dir: _generated_media
   secure: optional
 
 - url: /html
   static_dir: templates/html
   secure: optional
 
 - url: /.*
   script: common/appenginepatch/main.py
   secure: optional