1
votes

I know the way to access the flask app obj is using current_app, however, everytime I run that code I get this error: NameError: global name 'current_app' is not defined

What am I doing wrong here?

My folder structure is this:

/project
   gateway.py
   settings.py
   /app
      views.py
      models.py

I can't access the app object neither from views.py or models.py :S Always get the same error.

The views.py file declares a blueprint wich is registered in the gateway.py file.

I'm using current_app inside a view function inside the views.py file.

Hope you can help me.

1
Maybe you forgot to add from flask import current_app inside those files?Audrius Kažukauskas
Do you have the init.py defined ? If so where are you "creating" the current_app object? Are you importing what @AudriusKažukauskas said in your views.py?albertogg

1 Answers

3
votes

Make sure you have

from flask import Flask, current_app

in your code and make sure you call it correctly, because in some context it doesn't get called.