-
Hi, I got a NameError: name 'app' is not defined from this line I followed the sample code from https://reflex.dev/docs/events/background-events#terminating-background-tasks-on-page-close-or-navigation The difference is that the class State is in a separate file. If I put the class State in the same file as the app.py where the app = rx.App() is defined, it works as expected. Anyone seen this error and how to solve it? Thanks --Guang |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Beta Was this translation helpful? Give feedback.
-
@gwsu2008 to give you an actual answer to your question. There are two ways to get the
|
Beta Was this translation helpful? Give feedback.
@gwsu2008 to give you an actual answer to your question.
There are two ways to get the
app
reference without circular import issues.from myapp import app
inside the body of the background event function itself. This will delay the import, allowing the module to be fully initialized before you try to get a reference to it.from reflex.utils.prerequisites import get_app
. Thenget_app().app.event_namespace
(note this will beNone
if the app is not running).