Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MySQL Database Flask
#1
Hello all,

I'm just starting using Flask and I have some doubts where and how I should make my DB connection.

my app is currently organized as follows:
/
├── app/
│ ├── forms.py
│ ├── routes.py
│ ├── templates
│ └── ...
│ └── static
│ └── ...
├── flaskapp.py

on the routes.py I have a "index" and a "chart" route each one needs access to the DB (I'm using mysql.connector). Currently I'm doing the following at each route:

    mydb = mysql.connector.connect(
        host="localhost",
        user="foo",
        passwd="bar",
        database="foobar")
    mycursor = mydb.cursor()
I don't think it is correct to be doing this each time I need to use the DB. What should the correct way be? can you please provide an example?

looking forward your reply,
Best regards, Mauro.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  User Input to mySQL database newbie1 3 1,870 Aug-26-2020, 10:42 AM
Last Post: newbie1
  Flask export/upload database table in cvs/xlsx format steve87bg 4 2,433 Jun-19-2020, 01:46 PM
Last Post: steve87bg
  how to save the data from MySQL to CSV in Flask farah97 4 1,320 Jan-03-2020, 03:02 AM
Last Post: farah97
  Read Save RadioButtons from Database in Python Flask Webpage Gary8877 0 4,515 Apr-11-2019, 12:33 AM
Last Post: Gary8877
  How to format a datetime MySQL database field to local using strftime() nikos 6 1,709 Feb-24-2019, 06:32 PM
Last Post: nikos
  flask sqlite jinja accessing and updating database help pascale 5 1,939 Feb-11-2019, 03:49 PM
Last Post: pascale
  how i save the html form to flask database mebaysan 1 4,877 Feb-07-2019, 12:56 AM
Last Post: snippsat
  mysql database error brecht83 1 3,639 Dec-14-2018, 01:25 PM
Last Post: jeanMichelBain
  General advice web application - flask - database - cms bashage 6 2,996 Jan-31-2018, 06:07 PM
Last Post: frostbite

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020