def init_app(app): # mysql 数据库连接数据 app.config['SQLALCHEMY_DATABASE_URI'] = Config().get_sql_url() # 禁用追踪对象的修改并且发送信号(会需要额外内存) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False db.init_app(app)
from flask_restful import Resource, reqparse, Api #Instantiate a flask object app = Flask(__name__) #Instantiate Api object fluapi = Api(app) #Setting the location for the sqlite database app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///base.db' #Adding the configurations for the database app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['PROPAGATE_EXCEPTIONS'] = True #Import necessary classes from base.py from base import flu_data, db #Link the app object to the Movies database db.init_app(app) app.app_context().push() #Create the databases db.create_all() #Creating a class to create get, post, put & delete methods class Movies_List(Resource): #Instantiating a parser object to hold data from message payload parser = reqparse.RequestParser() parser.add_argument('director', type=str, required=False, help='Director of the movie') parser.add_argument('genre',
def config_db(app): db.init_app(app)