Get root path of Flask application

app.root_path contains the root path for the application. This is determined based on the name passed to Flask. Typically, you should use the instance path (app.instance_path) not the root path, as the instance path will not be within the package code. filename = os.path.join(app.instance_path, ‘my_folder’, ‘my_file.txt’)

Python Flask shutdown event handler

There is no app.stop() if that is what you are looking for, however using module atexit you can do something similar: https://docs.python.org/2/library/atexit.html Consider this: import atexit #defining function to run on shutdown def close_running_threads(): for thread in the_threads: thread.join() print “Threads complete, ready to finish” #Register the function to be called on exit atexit.register(close_running_threads) #start … Read more

Flask logging not working at all

Your (debug) logging messages are getting suppressed by Flask as you’re not running in debug mode. If you set the following flag to True, your code will work. app.run(debug=True) The messages will now appear as expected. BennyE$ python3 stackoverflow.py 2015-03-08 12:04:04,650 ERROR: firs test message… [in stackoverflow.py:31] * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit) … Read more

Update row (SQLAlchemy) with data from marshmallow

UPDATED, 2022-12-08 Extending the ModelSchema from marshmallow-sqlalchemy instead of Flask-Marshmallow you can use the load method, which is defined like this: load(data, *, session=None, instance=None, transient=False, **kwargs) Putting that to use, it should look like that (or similar query): node_schema.load(json_data, session= current_app.session, instance=Node().query.get(node_id)) And if you want to load without all required fields of Model, … Read more

Gunicorn ImportError: cannot import name ‘ALREADY_HANDLED’ from ‘eventlet.wsgi’ in docker

Installing older version of eventlet solved the problem: pip install eventlet==0.30.2 EDIT: you can use the newer versions like this: pip install eventlet==0.33.0 https://github.com/benoitc/gunicorn/archive/refs/heads/master.zip#egg=gunicorn==20.1.0 see: https://github.com/benoitc/gunicorn/pull/2581#issuecomment-994198667 thank you @jmunsch

Why did Flask start failing with “ImportError: cannot import name ‘url_quote’ from ‘werkzeug.urls'”?

I had the same problem. It is because Werkzeug 3.0.0 was released and Flask doesn’t specify the dependency correctly (requirements says Werkzeug>=2.2.0). This is why, Werkzeug 3.0.0 is still installed and Flask 2.2.2 isn’t made for Werkzeug 3.0.0. Solution: Just set a fix version for Werkzeug such as Werkzeug==2.2.2 in your requirements.txt and it should … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)