せかいや

いまいるここを、おもしろく http://sekai-in-the-box.appspot.com/

【GAE】【Python】エラー: File "C:\google_appengine\google\appengine\runtime\wsgi.py", line 255, in _LoadHandler

GAE Lancherにてデプロイ時、静的なページ(index.html)を表示させようとしてエラー発生。

■app.yaml

application: hogehoge
version: 1
runtime: python
api_version: 1

handlers:

static_dir: css

  • url: /.*

script: index.html


■発生エラー

File "C:\google_appengine\google\appengine\runtime\wsgi.py", line 196, in Handle

handler = _config_handle.add_wsgi_middleware(self._LoadHandler())

File "C:\google_appengine\google\appengine\runtime\wsgi.py", line 255, in _LoadHandler

handler = __import__(path[0])

ImportError: No module named index

■原因
wsgi.py の255行目を見てみると、記載したファイル名はpyファイルと期待しているよう。
handlersのscript要素に、htmlファイル名を記載してはいけなかったみたい。

path = self._handler.split('.')
handler = __import__(path[0])

■解決
適当なpyファイルを作成し、中で処理を記述しました

import cgi
import os

from google.appengine.ext.webapp import template
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
def get(self):
template_values = {}

path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))

application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)

def main():
run_wsgi_app(application)

if __name__ == "__main__":
main()

■公式サイト
色々詳しく書いてある。static_files属性を使えば良いみたい。帰ってきたらやってみよう。
GAE:Python アプリケーションの設定

https://developers.google.com/appengine/docs/python/config/appconfig?hl=en