41 lines
736 B
Python
41 lines
736 B
Python
from flask import Flask, jsonify
|
|
from dotenv import load_dotenv
|
|
|
|
from models import *
|
|
|
|
|
|
def create_app():
|
|
load_dotenv()
|
|
|
|
# Create Flask app load app.config
|
|
application = Flask(__name__)
|
|
application.config.from_object("config.ConfigClass")
|
|
|
|
application.app_context().push()
|
|
|
|
db.init_app(application)
|
|
|
|
# Create all tables
|
|
db.create_all()
|
|
|
|
@application.route('/')
|
|
def hello_world():
|
|
return 'Hello World!'
|
|
|
|
@application.route('/users')
|
|
def users():
|
|
res = []
|
|
for i in User.query.all():
|
|
res.append(i.as_dict())
|
|
|
|
return jsonify(res)
|
|
|
|
return application
|
|
|
|
|
|
app = create_app()
|
|
|
|
# Start development web server
|
|
if __name__ == '__main__':
|
|
app.run()
|