I am a beginner in python web frameworks and i have created a simple Python-Flask RESTful API which enables me to get infromation from a database using GET request but i have a problem in how can i use this API with any website python based frameworks because i know each framework has it's own way to conenct Urls with the code so it will not be just add the .py file to the website files and invoke it from the Url like php, so how can i use this flask APi in any website with python framework like (Django, Flask, ..etc)? Thanks.
This is my simple API:
from flask import Flask, request
from flask_restful import Resource, Api
from sqlalchemy import create_engine
from json import dumps
from flask_jsonpify import jsonify
import MySQLdb
app = Flask(__name__)
api = Api(app)
db = MySQLdb.connect("localhost", "root", "root", "x")
class macros(Resource):
def get(self):
cursor = db.cursor()
cursor.execute("select * from survey_macro") # This line will be changes from website to another
return jsonify({'macros':[i for i in cursor.fetchall()]})
api.add_resource(macros, '/macros') # Route_1
if __name__ == '__main__':
app.run(port='5002')