无法在Google App Engine上运行Flask调试模式 [英] Can't run Flask debug mode on Google App Engine
问题描述
文件/path/to/application/main.py,第14行,在< module>
@ app.route('/')
AttributeError:'DebuggedApplication'对象没有属性'route'
它不仅可以是'route',也可以是Flask应用程序的任何属性。
我的文件树看起来像这样,
application
__init__.py
main.py
...
flask
flaskext
werkzeug
werkzeug_debugger_appengine
...
app.yaml
在app.yaml我的目标是WSGI应用程序:
application:application_name
version:1
运行时:python27
api_version:1
threadsafe:true
uiltins:
- appstats:在
- admin_redirect:在
- deferred:
- remote_api:在
库:
- name:jinja2
版本:2.6
- name: markupsafe
版本:0.15
inbound_services:
- 预热
处理程序:
- url:。*
脚本:application.app
这里是 __ init __。py <
from flask import Flask
from werkzeug_debugger_appengine import get_debugged_app
##开始应用程序
app = Flask('application_name')
##配置
导入os
导入机密
app.debug = True
app.secret_key = secrets.SECRET_KEY
app.csrf_session_key = secrets.CSRF_SESSION_KEY
#自动设置基于App Engine dev的调试模式如果os.environ和os.environ ['SERVER_SOFTWARE']中的'SERVER_SOFTWARE'启动('Dev'):
app.debug = True
##扩展
如果app.debug:
app = get_debugged_app(app)
##其他
导入主
这样做没有werkzeug_appengine_debugger也没有工作。以下初始化:
app = DebuggedApplication(app,True)
仍会引发相同的异常。
在没有GAE +烧瓶教程或文章我看到这个问题。为什么会这样呢?
b应该是:
<$ c
$ b这是在Flask中添加中间件的建议方式 - 就像文档所说的那样,保留对
flask.Flask
应用程序类的引用。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. After trying to use werkzeug_appengine_debugger I have the following exception in console:
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.
My file tree looks like this, borrowed from flask-appengine-template:
application __init__.py main.py ... flask flaskext werkzeug werkzeug_debugger_appengine ... app.yaml
In app.yaml I'm targeting WSGI app:
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
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. The following intialization
app = DebuggedApplication(app, True)
still throws the same exception.
In no GAE + Flask tutorial or article I have seen this problem. 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."这篇关于无法在Google App Engine上运行Flask调试模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!