Как вывести результат из базы данных MySQL в мой FLASK RESTFULL API без юза SQLALCHEMY?

Тут у меня находиться API

Salon.py

from models import Plant, Salon, Employee
from flask import Flask
from flask_restful import Resource, Api
import pymysql

app = Flask(__name__)
api = Api(app)

class plant(Resource):
    def get(self):
        try:
            plant = Plant()
            return plant._generate_dict()
        except Exception:
            print("Eror!")

api.add_resource(plant, '/')

if __name__ == '__main__':
app.run(debug=True)

Тут основной код

Models.py

from framework.models import Model
import pymysql


class Plant(Model):
    def __init__(self):
        self.connection = pymysql.connect(host="localhost", user="root", password="1974", db="sql_plant")
        print("Successfully connected...")
        print("#" * 20)

def save(self):
    try:
        with self.connection.cursor() as cursor:
            l = input("Location: ")
            n = input("Name: ")
            d = int(input("Direcor id: "))
            insert_query = "INSERT INTO `Plant`(location, name, director_id) VALUES ('{}', '{}', '{}')".format(str(l), str(n), str(d))
            cursor.execute(insert_query)
            self.connection.commit()
    finally:
        self.connection.close()

def _generate_dict(self):
    try:
        cur = self.connection.cursor()
        cur.execute("SELECT * FROM Plant")
        for row in cur.fetchall():
            print(row[0], "|", row[1], "|", row[2], "|", row[3])
    finally:
        self.connection.close()

class Salon(Model):
def __init__(self):
    self.connection = pymysql.connect(host="localhost", user="root", password="1974", db="sql_plant")
    print("Successfully connected...")
    print("#" * 20)
def save(self):
    try:
        with self.connection.cursor() as cursor:
            n = input("Salon name: ")
            insert_query = "INSERT INTO `Salon`(name) VALUES ('{}')".format(str(n))
            cursor.execute(insert_query)
            self.connection.commit()
    finally:
        self.connection.close()

def _generate_dict(self):
    try:
        cur = self.connection.cursor()
        cur.execute("SELECT * FROM Salon")

        for row in cur.fetchall():
            print(row[0], "|", row[1])
    finally:
        self.connection.close()

class Employee(Model):
def __init__(self):
    self.connection = pymysql.connect(host="localhost", user="root", password="1974", db="sql_plant")
    print("Successfully connected...")
    print("#" * 20)
def save(self):
    try:
        with self.connection.cursor() as cursor:
            e = input("Email: ")
            n = input("Name: ")
            t = input("Department type: ")
            d = int(input("Department id: "))
            insert_query = "INSERT INTO `Employees`(email, name, department_type, department_id) VALUES ('{}', '{}', '{}', '{}')".format(str(e), str(n), str(t), str(d))
            cursor.execute(insert_query)
            self.connection.commit()
    finally:
        self.connection.close()

def _generate_dict(self):
    try:
        cur = self.connection.cursor()
        cur.execute("SELECT * FROM Employees")

        for row in cur.fetchall():
            print(row[0], "|", row[1], "|", row[2], "|", row[3], "|", row[4])
    finally:
        self.connection.close()

В Salon.py пытаюсь сделать вывод _generate_dict из Plant, на странице ничего нету но в самом пайтоне вывод присуствует


Ответы (0 шт):