def create_app(): app = Flask(__name__) # setup with the configuration provided app.config.from_object('config.DevelopmentConfig') # setup all our dependencies database.init_app(app) # register blueprint app.register_blueprint(app1) # app.register_blueprint(app2, url_prefix="/app2") return app
api.add_resource(RandomChooser, '/choose') api.add_resource(Puzzle, '/puzzle/<string:key>') api.add_resource(Score, '/score/<string:user_id>') @app.route('/') def index(): return redirect(url_for('login')) @app.route('/register') def register(): return render_template('register.html') @app.route('/login', methods=['GET']) def login(): return render_template('login.html') @app.route('/choose', methods=['GET']) def choose(): resp = make_response(render_template('puzzle.html')) resp.headers.set('Authorisation', "Bearer " + session['access_token']) return resp if __name__ == '__main__': database.init_app(app) app.run(port=5000, debug=True)
from flask_restful import Api from flask_jsglue import JSGlue from database import database, insert_queries from resources.topic import Topic from resources.formativeAssessment import FormativeAssessment from resources.test import Test from resources.quiz import Quiz from resources.answer import Answer import sys app = Flask(__name__) app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db' api = Api(app) jsglue = JSGlue(app) database.init_app(app) # this should be in the 'if is main' at the bottom of this file so that the database isn't re-initialized if 'app.py' is imported from another file, but that would mean that the database is never initialized if we run the app via Flask instead of Python @app.before_first_request def create_tables(): if '--create' in sys.argv or '-c' in sys.argv: database.create_all() if '--insert' in sys.argv or '-i' in sys.argv: for query in insert_queries: database.session.execute(query) database.session.commit() @app.route('/') def index(): return render_template('home.html')
api.add_resource(ProjectResource, "/projects/<int:project_id>") api.add_resource(DeploymentResource, "/projects/<int:project_id>/deploy") api.add_resource(SolutionListResource, "/projects/<int:project_id>/solutions") api.add_resource( SolutionDownloadResource, "/projects/<int:project_id>/solutions/<int:solution_id>/download") api.add_resource(SolutionResource, "/projects/<int:project_id>/solutions/<int:solution_id>") api.add_resource(DataPreviewRersource, "/preview") api.add_resource(OnlinePredictionResource, "/projects/<int:project_id>/prediction/online") api.add_resource(UserSignupResource, "/users/signup") api.add_resource(UserSigninResource, "/users/signin") api.add_resource(PaymentResource, "/tokens") api.add_resource(NotebookListResource, "/notebooks") api.add_resource(NotebookResource, "/notebooks/<int:notebook_id>") api.add_resource(NotebookStartResource, "/notebooks/start/<int:notebook_id>") api.add_resource(NotebookStopResource, "/notebooks/stop/<int:notebook_id>") api.add_resource(NotebookUrlResource, "/notebooks/url/<int:notebook_id>") if __name__ == "__main__": # Initialize database db.init_app(app) # Don't use debug=True in production app.run(port=5000, host="0.0.0.0", debug=True)