[英]Can't run Flask debug mode on Google App Engine
I'm running Flask 0.9 / Werkzeug 0.8.3 on Google App Engine with Python 2.7, and I desperately want Werkzeug debugger running. 我正在使用Python 2.7在Google App Engine上运行Flask 0.9 / Werkzeug 0.8.3,我迫切希望运行Werkzeug调试器。 After trying to use werkzeug_appengine_debugger I have the following exception in console: 尝试使用werkzeug_appengine_debugger后,我在控制台中有以下异常:
File "/path/to/application/main.py", line 14, in <module>
@app.route('/')
AttributeError: 'DebuggedApplication' object has no attribute 'route'
It can be not only 'route', but whatever attribute Flask application can have. 它不仅可以是'route',还可以是Flask应用程序可以拥有的任何属性。
My file tree looks like this, borrowed from flask-appengine-template : 我的文件树看起来像这样,借用于flask-appengine-template :
application
__init__.py
main.py
...
flask
flaskext
werkzeug
werkzeug_debugger_appengine
...
app.yaml
In app.yaml I'm targeting WSGI app: 在app.yaml我的目标是WSGI应用程序:
application: application_name
version: 1
runtime: python27
api_version: 1
threadsafe: true
builtins:
- appstats: on
- admin_redirect: on
- deferred: on
- remote_api: on
libraries:
- name: jinja2
version: "2.6"
- name: markupsafe
version: "0.15"
inbound_services:
- warmup
handlers:
- url: .*
script: application.app
And here is the contents of __init__.py
这是__init__.py
的内容
from flask import Flask
from werkzeug_debugger_appengine import get_debugged_app
## Starting app
app = Flask('application_name')
## Configuration
import os
import secrets
app.debug = True
app.secret_key = secrets.SECRET_KEY
app.csrf_session_key = secrets.CSRF_SESSION_KEY
# Auto-set debug mode based on App Engine dev environ
if 'SERVER_SOFTWARE' in os.environ and os.environ['SERVER_SOFTWARE'].startswith('Dev'):
app.debug = True
## Extensions
if app.debug:
app = get_debugged_app(app)
## Everything else
import main
It doesn't work without werkzeug_appengine_debugger either. 没有werkzeug_appengine_debugger它也行不通。 The following intialization 以下初始化
app = DebuggedApplication(app, True)
still throws the same exception. 仍然抛出相同的异常。
In no GAE + Flask tutorial or article I have seen this problem. 在没有GAE + Flask教程或文章中我看到了这个问题。 Why could that happen? 为什么会这样?
app = DebuggedApplication(app, True)
should be: 应该:
app.wsgi_app = DebuggedApplication(app.wsgi_app, True)
This is the recommended way to add middleware in Flask - that way you can, as the docs say, "keep a reference to the flask.Flask
application class." 这是在Flask中添加中间件的推荐方法 - 正如文档所说,这样你可以“保留对flask.Flask
应用程序类的引用”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.