def create_app() -> Flask: """ Factory pour la création de l'application Flask :return: L'application flask créé """ # Ici on peut rajouter une initialisation de la configuration par un fichier json, # Si l'on en veut un autre que celui par defaut # config_app.init_from_json_file(json_file) configuration_flask = ConfigurationFlask() current_app = Flask(__name__, static_folder=web_static_dir + '/', template_folder=web_templates_dir + '/') current_app.config.from_object(configuration_flask) current_app.app_context().push() # this does the binding blueprint_registrations(current_app) # So we can upload files # We need to do secret = secrets.token_urlsafe(32) current_app.secret_key = secret # Imperatif de faire l'init_db() après l'initialisation par le fichier de configuration # si l'on veut des valeurs autre que celles par défaut init_db() jsglue = JSGlue() jsglue.init_app(current_app) return current_app
def create_app(): app = Flask(__name__) app.config.from_object(Config) db_session = init_db(app) scheduler = BackgroundScheduler() scheduler.start() scheduler.add_job(processing_timeout, 'interval', seconds=60) scheduler.add_job(old_files_removals, 'interval', hours=24) Path(app.config['PROCESSED_REQUESTS_FOLDER']).mkdir(parents=True, exist_ok=True) Path(app.config['MODELS_FOLDER']).mkdir(parents=True, exist_ok=True) Path(app.config['UPLOAD_IMAGES_FOLDER']).mkdir(parents=True, exist_ok=True) Bootstrap(app) Dropzone(app) notification = db_session.query(Notification).first() if notification is not None: notification.last_notification = datetime.datetime(1970, 1, 1) else: notification = Notification(datetime.datetime(1970, 1, 1)) db_session.add(notification) db_session.commit() jsglue = JSGlue() jsglue.init_app(app) from app.main import bp as main_bp app.register_blueprint(main_bp) return app
def create_app(test_config=None, SECRET_KEY='dev', instance_path=''): # create and configure the app if not instance_path: app = Flask(__name__, instance_relative_config=True) else: app = Flask(__name__, instance_path=instance_path) app.config.from_mapping( SECRET_KEY=SECRET_KEY, DATABASE=os.path.join(app.instance_path, 'demosaurus.sqlite'), ) jsglue = JSGlue() jsglue.init_app(app) if test_config is None: # load the instance config, if it exists, when not testing app.config.from_pyfile('config.py', silent=True) else: # load the test config if passed in app.config.from_mapping(test_config) # ensure the instance folder exists try: os.makedirs(app.instance_path) except OSError: pass from . import db db.init_app(app) from . import publication app.register_blueprint(publication.bp) from . import link_thesaurus app.register_blueprint(link_thesaurus.bp) from . import subject_headings app.register_blueprint(subject_headings.bp) from . import contributor app.register_blueprint(contributor.bp) # a simple page that says hello @app.route('/hello') def hello(): return 'Hello, World!' @app.route('/favicon.ico') def favicon(): return send_from_directory(os.path.join(app.root_path, 'static'), 'favicon.ico', mimetype='image/vnd.microsoft.icon') @app.route('/') def index(): return render_template('/') return app
def register_extensions(app): """Register Flask extensions.""" assets.init_app(app) bcrypt.init_app(app) cache.init_app(app) db.init_app(app) csrf_protect.init_app(app) login_manager.init_app(app) debug_toolbar.init_app(app) migrate.init_app(app, db) jsglue = JSGlue() jsglue.init_app(app) return None
from ontology.utils import utils from ontology.wallet.wallet_manager import WalletManager from werkzeug.utils import secure_filename # ipfs_daemon = subprocess.Popen("ipfs daemon", stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True) static_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static') template_folder = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates') app = Flask('IPAblum', static_folder=static_folder, template_folder=template_folder) app.config.from_object('default_settings') ImageFile.LOAD_TRUNCATED_IMAGES = True jsglue = JSGlue() jsglue.init_app(app) default_identity_account = None default_wallet_account = None try: ipfs = ipfsapi.connect(app.config['IPFS_HOST'], app.config['IPFS_PORT']) except Exception: print('Failed to establish a new connection to IPFS node...') exit(1) def remove_file_if_exists(path): if os.path.isfile(path): os.remove(path) return True return False
from flask import Flask, render_template, jsonify, url_for, request from flask_jsglue import JSGlue import random from uuid import uuid1 app = Flask(__name__) jsglue = JSGlue() jsglue.init_app(app) # 让js文件中可以使用url_for方法 results = [] chars = 'ABCDEFGHIJKLMNOPQRSTUVWSYZ' results.append({'name': 'vue.js+flask+element-ui简易Demo', 'flag': 'true'}) results.append({ 'name': '代码请戳github', 'flag': 'true', 'url': 'https://github.com/qianbin01/Vue-flask' }) for i in range(5): results.append({'name': random.choice(chars), 'index': str(uuid1())}) @app.route('/') def index(): return render_template('index.html') @app.route('/get_data') def get_base_data(): return jsonify({'results': results}) @app.route('/add', methods=['POST'])
from flask import Flask, request, render_template, redirect, jsonify, render_template_string from flask_jsglue import JSGlue # this is use for url_for() working inside javascript which is help us to navigate the url import util import os from werkzeug.utils import secure_filename application = Flask(__name__) application.debug = True # JSGlue is use for url_for() working inside javascript which is help us to navigate the url jsglue = JSGlue() # create a object of JsGlue jsglue.init_app(application) # and assign the app as a init app to the instance of JsGlue util.load_artifacts() #home page @application.route("/") def home(): return render_template("home.html") #classify plant @application.route("/classifyPlant", methods = ["POST"]) def classifyPlant(): image_data = request.files["file"] #save the image to upload basepath = os.path.dirname(__file__) image_path = os.path.join(basepath, "uploads", secure_filename(image_data.filename)) image_data.save(image_path) predicted_value, details = util.classify_plant(image_path) os.remove(image_path) return jsonify(predicted_value=predicted_value, details=render_template_string(details))
from flask import Flask, g, url_for, render_template, request, redirect, flash, session, abort, Markup from oauth2client.client import flow_from_clientsecrets import httplib2 import json from apiclient.discovery import build from flask_jsglue import JSGlue from model.redis_model import RedisModel import lib.common as common from lib.mysocket import MySocket from flask_socketio import join_room jsglue = JSGlue() app = Flask(__name__) jsglue.init_app(app) app.config.from_object('config.config') app.config.from_envvar('PPOSTER_SETTINGS', silent=True) model = RedisModel(app.config) my_socket = MySocket(app, async_mode) socketio = my_socket.get_socketio() #socketio = SocketIO(app, async_mode=async_mode) thread = None RESERVED_ALIASES = ['login', 'register', 'google_auth', 'auth_return', 'logout', 'timelinejson', 'public', 'add_tweet', 're_tweet', 'remove_tweet', 'add_comment', 'notifications'] def is_reserved(alias): return alias in RESERVED_ALIASES or alias.startswith('tweet')