本文介绍了无法在Google App Engine上运行Flask调试模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我在Python App Engine上用Python 2.7运行Flask 0.9 / Werkzeug 0.8.3,我非常想让Werkzeug调试器运行。尝试使用 werkzeug_appengine_debugger 后,我在控制台中发现以下异常: 文件/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 应该是: $ 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 ...flaskflaskextwerkzeugwerkzeug_debugger_appengine...app.yamlIn app.yaml I'm targeting WSGI app:application: application_nameversion: 1runtime: python27api_version: 1threadsafe: truebuiltins:- appstats: on- admin_redirect: on- deferred: on- remote_api: onlibraries:- name: jinja2 version: "2.6"- name: markupsafe version: "0.15"inbound_services:- warmuphandlers:- url: .*script: application.appAnd here is the contents of __init__.pyfrom flask import Flaskfrom werkzeug_debugger_appengine import get_debugged_app## Starting appapp = Flask('application_name')## Configurationimport osimport secretsapp.debug = Trueapp.secret_key = secrets.SECRET_KEYapp.csrf_session_key = secrets.CSRF_SESSION_KEY# Auto-set debug mode based on App Engine dev environif 'SERVER_SOFTWARE' in os.environ and os.environ['SERVER_SOFTWARE'].startswith('Dev'): app.debug = True## Extensionsif app.debug: app = get_debugged_app(app)## Everything elseimport mainIt doesn't work without werkzeug_appengine_debugger either. The following intializationapp = 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调试模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 18:56
查看更多