简体   繁体   中英

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. 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."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM