I am trying to connect mysql database with python-flask app. My app.py looks like this
app = Flask(__name__, template_folder='templates', static_folder='static')
#config Database
connection = mysql.connector.connect(
user = 'localhost',
password = '',
host='127.0.0.1',
port = 3306,
database = 'test'
)
@app.route('/', methods=['GET', 'POST'])
def index():
cursor = connection.cursor()
cursor.execute("SELECT name, rating, number, type, image from place")
data = cursor.fetchall()
cursor.close()
connection.close()
return render_template('index.html', data = data)
if __name__ == '__main__':
app.run(host='0.0.0.0')
But when I browse it "Unable to connect". MySql sever is on.
In the terminal it shows
You are running "Pyhton app.py" in terminal. It needs to run "Flask run" in terminal
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.