def create_api(mode='development'): instance_path = path.join(path.abspath(path.dirname(__file__)), '{}_instance'.format(mode)) app = Flask(__name__, instance_path=instance_path) app.config.from_object('configdb') app.config.update(MAIL_SERVER='smtp.gmail.com', MAIL_PORT=465, MAIL_USE_SSL=True, MAIL_DEFAULT_SENDER='*****@*****.**', MAIL_USERNAME='******', MAIL_PASSWORD='******') @app.after_request def after_request(response): response.headers.add('Access-Control-Allow-Origin', '*') response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization') response.headers.add('Access-Control-Allow-Methods', 'POST') return response set_resources_in_app(app) db.init_app(app=app) mail.init_app(app) return app
def create_app(): app = Flask(__name__) api = Api(app) app.config.from_object('config.default') app.config.from_envvar('APP_SETTINGS', silent=False) app.add_url_rule('/api/login', 'login', _get_token) from models.base import db db.init_app(app) from controllers.index import Index from controllers.user import UsersList, UserSingle from controllers.tasks import TaskSingle, Tasks, AssignTask from controllers.comments import Comments from controllers.reports import UserComments, TaskStats app.before_request(db_connect.before_request) app.after_request(db_connect.after_request) app.add_url_rule('/api/tasks/<int:task_id>/comments', view_func=Comments.as_view(COMMENTS)) api.add_resource(Index, '/api/index') api.add_resource(UsersList, '/api/users') api.add_resource(UserSingle, '/api/users/<int:user_id>') api.add_resource(Tasks, '/api/tasks') api.add_resource(TaskSingle, '/api/tasks/<int:task_id>') api.add_resource(AssignTask, '/api/assign_task') api.add_resource(UserComments, '/api/reports/user_comments') api.add_resource(TaskStats, '/api/reports/task_stats') return app
def create_app(): """ 创建 app 实例 """ app = Flask(__name__) # 添加配置 app.config.from_object('app.setting') app.config.from_object('app.secure') # 注册蓝图 register_blueprint(app) # 初始化 flask-sqlalchemy db.init_app(app) # 根据模型创建数据表(model 在 web 中引用) # db.create_all(app=app) with app.app_context(): db.create_all() # 初始化 flask-login login_manager.init_app(app) # 指定登录视图函数的 endpoint 和 提示消息 login_manager.login_view = 'web.login' login_manager.login_message = '请先登录或注册' # 初始化 flask-mail mail.init_app(app) return app
def create_app(name): app = Flask(name) init_config(app) db.init_app(app) init_login(app) return app
def create_app(): """ Create a Flask application using the app factory pattern. :param settings_override: Override settings :return: Flask app """ app = Flask(__name__) app.config.from_object('config') from security import authenticate, identity JWT(app, authenticate, identity) routes(app) extensions(app) db.init_app(app) return app
def create_app(): app = Flask(__name__) app.config.update({ 'SECRET_KEY': os.getenv("FLASK_SECRET"), 'OAUTH2_REFRESH_TOKEN_GENERATOR': True, 'SQLALCHEMY_TRACK_MODIFICATIONS': False, 'SQLALCHEMY_DATABASE_URI': os.getenv("SQLALCHEMY_DATABASE_URI"), }) db.init_app(app) config_oauth(app) config_cli(app) app.register_blueprint(index_bp) app.register_blueprint(auth_bp, url_prefix="/auth") return app
def create_app(conf): app = Flask(__name__) app.config.from_object(conf) CORS(app, resources={r"/v1/*": {"origins": "*"}}) db.init_app(app) with app.app_context(): db.drop_all() db.create_all() @app.route('/') def welcome(): return 'Welcome to word counting website!' api = Api(app, catch_all_404s=True) # mapping resource with routes api.add_resource(StatisticResource, '/v1/statistics/<int:statistic_id>') api.add_resource(StatisticResourceList, '/v1/statistics') return app
def create_api(mode='development'): instance_path = path.join(path.abspath(path.dirname(__file__)), '{}_instance'.format(mode)) app = Flask(__name__, instance_path=instance_path) app.config['JWT_SECRET_KEY'] = 'is secret' app.config.from_object('configdb') @app.after_request def after_request(response): response.headers.add('Access-Control-Allow-Origin', '*') response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization') response.headers.add('Access-Control-Allow-Methods', 'POST') return response app.add_url_rule('/v1/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True)) db.init_app(app=app) return app
api_url_prefix = app.config['API_URL_PREFIX'] app.register_blueprint(auth_blueprint, url_prefix=api_url_prefix) app.register_blueprint(object_blueprint, url_prefix=api_url_prefix) app.register_blueprint(routes_blueprint, url_prefix=api_url_prefix) app.register_blueprint(review_blueptint, url_prefix=api_url_prefix) app.register_blueprint(place_blueptint, url_prefix=api_url_prefix) app.register_blueprint(public_place_blueptint, url_prefix=api_url_prefix) app.register_blueprint(historical_person_blueptint, url_prefix=api_url_prefix) app.register_blueprint(category_blueprint, url_prefix=api_url_prefix) app.register_blueprint(city_blueprint, url_prefix=api_url_prefix) app.register_blueprint(user_blueprint, url_prefix=api_url_prefix) app.register_blueprint(admin_blueprint, url_prefix=api_url_prefix) app.register_blueprint(translation_command_blueprint) app.register_blueprint(avatar_command_blueprint) db.init_app(app) jwt = JWTManager(app) with app.app_context(): migrate = Migrate(app, db) bcrypt_init() avatars_init() osrm_init() translation_init() @app.route(api_url_prefix + '/<path:path>') def not_found_api(path): abort(404) return
def register_plugin(app): from models.base import db db.init_app(app) with app.app_context(): db.create_all()
from functools import wraps from flask import (g, request, Response, Flask, jsonify) from flask.ext.httpauth import HTTPBasicAuth from models.base import db from services.cyclopedia_service import CyclopediaService from services.user_service import UserService from services.entry_service import EntryService from services.authentication_service import AuthenticationService from presenters.user_presenter import UserPresenter from presenters.cyclopedia_presenter import CyclopediaPresenter from presenters.entry_presenter import EntryPresenter app = Flask(__name__) app.config.from_object('config.DevelopmentConfig') app.auth = HTTPBasicAuth() db.init_app(app) def authenticate(): """Sends a 401 response that enables basic auth""" return Response('Could not verify your access level for that URL.\n' 'You have to login with proper credentials', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'}) def require_apikey(fn): @wraps(fn) def _wrap(*args, **kwargs): auth = request.authorization if not auth:
def init_app(app): db.init_app(app) # James: This block of code only run as start server. do not run it on db migration or upgrade if app.import_name == 'wsgi': with app.app_context(): db.metadata.create_all(db.engine)