cursor
반응형
-
[Python] Flask-MySQL 데이터 삽입(INSERT)하기Backend/Flask 2021. 5. 6. 23:19
# app.py import os from flask import Flask, jsonify, request from flask_mysqldb import MySQL app = Flask(__name__) mysql = MySQL(app) @app.route('/', methods=['GET', 'POST']) def visit(): if request.method == 'POST': name = request.json['visitor_name'] # mysql 접속 후 cursor 생성하기 cur = mysql.connection.cursor() # DB 데이터 삽입하기 cur.execute("INSERT INTO visits (visitor_name) VALUES(%s)", [name]) # DB에 ..