Flask/SQLAlchemy - How to globally use latin-1 instead of UTF-8? Flask/SQLAlchemy - How to globally use latin-1 instead of UTF-8? flask flask

Flask/SQLAlchemy - How to globally use latin-1 instead of UTF-8?


You can set the encoding of the SQLAlchemy connection to MySQL in the connection parameters:

create_engine('mysql+mysqldb:///mydb?charset=latin1')

See the SQLAlchemy documentation on MySQL, unicode section.


First, read the unicode chapter on Flask website at:http://flask.pocoo.org/docs/unicode/. It says "if you are using non-Unicode characters in your Python files you have to tell Python which encoding your file uses."

To do this, you can add the following in beginning of the python file. This tells the interpreter what encoding to use.

# coding: latin1