Alejandro A
Alejandro A

Reputation: 1190

flask before_request can't access request variable

I have a simple flask app:

def create_app():
    config_name = 'testing_local'

    app = Flask(__name__)
    app.config.from_object(CONFIG_BY_NAME[config_name])
    app.url_map.converters['bool'] = BooleanConverter
    @app.before_request
    def incoming_request_logging():
        print(request)
    return app

I get the error:

Undefined variable 'request'

I thought the wrapper included the request object when called?

In this example, first approved answer seems like the request object is inherited? Can anyone link me to a full example? How can I retrieve this variable?

Upvotes: 2

Views: 1135

Answers (1)

dewDevil
dewDevil

Reputation: 391

I guess declaring this at top of your program might solve your issue, if I think what you said it is:

from flask import request

Upvotes: 4

Related Questions