Attempted to generate a URL without the application context being pushed. This has to be executed when application context is available.
Package:
flask
56479

Exception Class:
RuntimeError
Raise code
""" am _anchor: if provided this is added as anchor to the URL.
:param _method: if provided this explicitly specifies an HTTP method.
"""
appctx = _app_ctx_stack.top
reqctx = _request_ctx_stack.top
if appctx is None:
raise RuntimeError(
"Attempted to generate a URL without the application context being"
" pushed. This has to be executed when application context is"
" available."
)
# If request specific information is available we have some extra
# features that support "relative" URLs.
if r
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/pallets/flask/blob/83f7efa04708a22c9701488f0f29b59c2b756bef/src/flask/helpers.py#L271Ways to fix
Summary:
The url_for function must always be called within the application context. i.e within a view, with app.app_context, by manually pushing the app ctx stack.
Code to reproduce:
from flask import url_for, Flask
app = Flask(__name__)
@app.route("/")
def index():
return ""
print(url_for("app.index"))
app.run()
Code to fix
from flask import url_for, Flask
app = Flask(__name__)
@app.route("/")
def index():
print(url_for("app.index")) # call within a view
return ""
with app.app_context():
print(url_for("app.index")) # or Call with context
app.run()
Add a possible fix
Please authorize to post fix