-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dash callbacks raising Flask 'RuntimeError: Working outside of request context.' #966
Comments
This kind of question is a better fit for https://community.plot.ly/c/dash, but I'll take a quick stab at it here: I'm a bit surprised it works with the layout in a function, as we tend to call that outside of requests as well for validation purposes. That kind of usage wouldn't care about the username, so you could always wrap the If you want to discuss further, please open a community thread - folks there likely have more experience with Flask login and may have other ideas to share. |
Thanks for the suggestion - it worked! It is very simple but don't think I found such answer when was searching today. This callback seems to solve my problem:
Also there is no need to put app layout in the function now. |
Nice! I wouldn't think you'd need the |
Yes - you are right. Changed to:
Thanks again! |
I just spent a bit of time being confused about this and I think the same thing might have been what threw off @Mudyla, so for future readers: You can always use the request context inside a callback. You can sometimes use it in a layout function. But you can't use it in a layout function if you define at least one callback. When the callback is initially registered, it is validated against the layout: see |
Hi,
Not sure if it is a bug or me not knowing how to do this properly but I am trying to make a Dash app with Flask login and home page. User would be redirected to Dash app when link clicked on home page. My app structure is as below with Dash app in
app1.py
:I wanted to pass logged user name into Dash app but kept getting 'RuntimeError: Working outside of request context.' error. After multiple searches I found a solution which involved putting app layout into function. It works fine unless any callback is added. Is there a solution for this? I tried adding callbacks into another function but it didn't do anything.
Code for
app1.py
:Code for
routes.py
:Other files are pretty much standard. I can paste those later if needed.
Traceback:
Let me know if any other details are needed. Thanks!
The text was updated successfully, but these errors were encountered: