def setUp(self): self.app = app.test_client() with app.app_context(): db.session.close() db.drop_all() db.create_all() setup_db(db.session)
def setUp(self): self.app = app.test_client() with app.app_context(): db.session.close() db.drop_all() db.create_all() setup_db(db.session) app.config['MONTRACKER_SERVER_ADDR'] = 'http://127.0.0.1:10000' app.config['MONTRACKER_SERVER_API_VERSION'] = 'v1' app.config['ARCGIS_PATH_PREFIX'] = 'http://127.0.0.1:11000' app.config['ARCGIS_PATH_SUFFIX'] = '/maps'
def create_app() -> Flask: locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8') server = Flask( __name__, static_folder=Defaults.FRONTEND_DIR, template_folder=Defaults.FRONTEND_DIR, ) server.json_encoder = DefaultJSONEncoder setup_logging() setup_errors(server) add_views(server) setup_db(server) init_db(server) @server.after_request def log_access(response): data = "<not printable>" if response.headers.get("Content-Type") == "application/json": try: data = response.get_data().decode("utf-8") except UnicodeDecodeError: pass log_message = None try: log_message = json.loads(data) except json.JSONDecodeError: log_message = data structlog.get_logger("access").info("RESPONSE", status=response.status_code, data=log_message) return response init_plotly_dash(server) return server
from flask_login import LoginManager from .admin import admin_routes from .auth import auth_routes from .seller import seller_routes from .buyer import buyer_routes from app.database import setup_db from app.login import login_manager from flask import Blueprint, Flask app = Flask(__name__) app.secret_key = '904872903489023kldnkansdkj0923480932' app.debug = True app.register_blueprint(admin_routes.admin_bp) app.register_blueprint(auth_routes.auth_bp) app.register_blueprint(seller_routes.seller_bp) app.register_blueprint(buyer_routes.buyer_bp) setup_db(app) login_manager.init_app(app)
return redirect(url_for('main.four_o_four')) app.register_error_handler(404, page_not_found) app.register_error_handler(400, not_found) from .routes import auth, main, editor, seller, payment, order app.register_blueprint(auth.auth_bp) app.register_blueprint(main.main_bp) app.register_blueprint(editor.editor_bp) app.register_blueprint(seller.seller_bp) app.register_blueprint(payment.payment_bp) app.register_blueprint(order.order_bp) from app.database import setup_db setup_db(app, environ.get('DATABASE_PATH')) from flask_login import LoginManager login_manager = LoginManager() login_manager.init_app(app) from app.models import User @login_manager.user_loader def load_user(id): return User.query.get(id)
def run(self): from app.database import db, setup_db with app.app_context(): setup_db(db.session)
def setup_db(force: bool): database.setup_db(force) print('Database set up successfully')
def serve(**kwargs): database.setup_db() from app import app uvicorn.run(app, **kwargs)
from flask import Flask, Blueprint from flask_login import LoginManager import os app = Flask(__name__) app.config['SECRET_KEY'] = os.environ.get('SECRET_KEY') from .routes import main, admin, auth app.register_blueprint(main.main_bp) app.register_blueprint(admin.admin_bp) app.register_blueprint(auth.auth_bp) from app.database import setup_db setup_db(app, os.environ.get('DB_PATH')) login_manager = LoginManager() login_manager.init_app(app) from app.models import Admin @login_manager.user_loader def load_user(id): return Admin.query.get(int(id))
from flask import Flask, Blueprint from flask_login import LoginManager app = Flask(__name__) app.config['TEMPLATES_AUTO_RELOAD'] = True app.config.from_envvar('APP_SETTINGS') from .routes import main, auth app.register_blueprint(main.main_bp) app.register_blueprint(auth.auth_bp) from app.database import setup_db setup_db(app, app.config['DATABASE_PATH']) login_manager = LoginManager() login_manager.init_app(app) from app.models import User @login_manager.user_loader def load_user(id): return User.query.get(id)