AppEngineプロジェクトの構造を次のように設定しています。
- ProjectRoot
- app.yaml
- index.yaml
- main.py
- 静的[ディレクトリ]
- index.html
- アプリ[ディレクトリ]
- script1.py
- script2.py
私のapp.yamlは次のようになります
application: appname
version: 1
runtime: python27
api_version: 1
threadsafe: no
handlers:
- url: /(.*\.html)
mime_type: text/html
static_files: static/\1
upload: static/(.*\.html)
expiration: "1h"
# application scripts
- url: /app/(.+)
script: main.py
# index files
- url: /(.+)/
static_files: static/\1/index.html
upload: static/(.+)/index.html
expiration: "15m"
- url: /(.+)
static_files: static/\1/index.html
upload: static/(.+)/index.html
expiration: "15m"
# site root
- url: /
static_files: static/index.html
upload: static/index.html
expiration: "15m"
libraries:
- name: webapp2
version: "2.5.1"
私のmain.pyは、単にデフォルトの「HelloWorld」サンプルアプリケーションです。
#!/usr/bin/env python
import webapp2
class MainHandler(webapp2.RequestHandler):
def get(self):
self.response.out.write('Hello world!')
#print("Executing script!")
app = webapp2.WSGIApplication([(r'/app/(.*)', MainHandler)],
debug=True)
これで、静的htmlに期待どおりにアクセスできます。app.yamlで指定されたmain.pyスクリプトへのURLマッピングが機能し、スクリプトが実行されていることがわかります。私が抱えている問題は、main.pyのWSGIApplicationに指定されるURLマッピングにあります。次のURLを使用してアプリケーションスクリプトにアクセスできるようにしたい:localhost:808x / app/パターンを使用してすでに試したもの:
r'/app/(.*)'
r'/(.*)'
r'/'
r'/app/'
上記のパターンのいずれも、「get」応答ハンドラーが呼び出されることにはなりません(つまり、「HelloWorld」応答が取得されません)。ドキュメントから自分が間違っていることを拾い集めてみました。結局のところ、正規表現を理解するだけだと思います。アプリケーションハンドラーをマップするために必要なパターンを誰かが教えてくれる可能性はありますか?