如何将Flask导入appengine

时间:2015-09-23 13:24:15

标签: python google-app-engine flask

得到可爱的错误:

ERROR    2015-09-23 13:14:12,500 cgi.py:122] Traceback (most recent call last):
  File "public/run.py", line 2, in <module>
    from src import app
  File "public/src/__init__.py", line 1, in <module>
    from flask import Flask
ImportError: No module named flask

我已使用public/lib将{flask}安装到pip install -t lib -r requirements.txt

  

公共/ appengine_config.py

from google.appengine.ext import vendor

# Add any libraries installed in the "lib" folder
vendor.add('lib')

# also does not work
# import os
# vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))
  

公共/ app.yaml中

version: 1
runtime: python27
api_version: 1
threadsafe: false

handlers:
- url: /static
  static_dir: src/static

- url: /
  script: run.py
  

公共/ run.py

from google.appengine.ext.webapp.util import run_wsgi_app
from src import app

run_wsgi_app(app)
  

公共/ SRC / __初始化__。PY

from flask import Flask
# import settings

app = Flask('app')
# app.config.from_object('src.settings')

import views

2 个答案:

答案 0 :(得分:2)

看看Starter Project。更重要的是,您应该将app.yaml更改为指向flask wsgi app。

- url: .*
  script: src.app

run.py脚本和run_wsgi_app()是运行应用程序的旧方式,不应使用。

答案 1 :(得分:2)

您可能还想查看gae-init项目,因为它使用Flask并构建在GAE上。我发现这是一种快速启动和运行的好方法。