Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask application with mysql tutorial [closed]

Tags:

mysql

flask

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
like image 273
Mike Sila Avatar asked Aug 10 '26 12:08

Mike Sila


1 Answers

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.

like image 127
Martinez Avatar answered Aug 13 '26 08:08

Martinez