In the flask tutorial at Step 2: Application Setup Code, I'd like to use mysql instead of sqlite3. Do I just do this:
# all the imports
import mysql
I would use Flask-SQLAlchemy then you can replace the tutorial code below:
# configuration
DATABASE = '/tmp/flaskr.db'
....
def connect_db():
return sqlite3.connect(app.config['DATABASE'])
with this
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://username:password@server/db'
db = SQLAlchemy(app)
You may find that learning SQLAchemy using Flask-SQLAlchemy with Flask will save you lots of time later on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With