#!/usr/bin/env python from flask.ext.script import Manager, Shell from flask.ext.migrate import Migrate, MigrateCommand from apps import create_app from apps.models import db from apps.models.User import login_manager from apps.models import User, Role, Comment # Flask app config: app = create_app('videodata') manager = Manager(app) # add Flask-Script migrate = Migrate( app, db ) # add Flask-Migrate to manage database // user python run db init to create Migrate Database manager.add_command('db', MigrateCommand) def make_shell_context(): return dict(app=app, db=db, User=User.User, Role=Role.Role, Comment=Comment.Comment) if __name__ == '__main__': login_manager.init_app(app) manager.add_command( "shell", Shell(make_context=make_shell_context)) # add shell env manager.run()
from sys import exit from decouple import config from apps.config import config_dict from apps import create_app, db # WARNING: Don't run with debug turned on in production! DEBUG = config('DEBUG', default=True, cast=bool) # The configuration get_config_mode = 'Debug' if DEBUG else 'Production' try: # Load the configuration using the default values app_config = config_dict[get_config_mode.capitalize()] except KeyError: exit('Error: Invalid <config_mode>. Expected values [Debug, Production] ') app = create_app(app_config) Migrate(app, db) if DEBUG: app.logger.info('DEBUG = ' + str(DEBUG)) app.logger.info('Environment = ' + get_config_mode) app.logger.info('DBMS = ' + app_config.SQLALCHEMY_DATABASE_URI) if __name__ == "__main__": app.run()
from flask import Flask from flask_script import Manager,Server from flask_migrate import MigrateCommand from apps import create_app from apps.settings import DEVELOP app=create_app(DEVELOP) manager=Manager(app) manager.add_command('start',Server(port=8000)) manager.add_command('db',MigrateCommand) if __name__ == '__main__': manager.run()
from apps import create_app config_str = "apps.settings.DevCMSConfig" app = create_app(config_str) if __name__ == '__main__': with app.app_context(): from apps.models import db db.create_all() app.run()
def fn(): app = create_app('develop') # 创建一个app用于检测 tool = Tool() tool.get_data()
import os from apps import create_app from flask.ext.script import Server, Shell, Manager from flask.ext.stormpath import StormpathManager # from rhodb.database import db from apps import db def create_manager(app, db): """ This function creates and configures a Flask-Script manager object. """ manager = Manager(app) manager.add_command("runserver", Server()) def make_shell_context(): return dict(app=app, db=db) manager.add_command("shell", Shell(make_context=make_shell_context)) return manager # Expose app & manager app = create_app(os.getenv('FLASK_CONFIG') or 'default') manager = create_manager(app, db) # If main, run the manager. # if __name__ == "__main__": manager.run()
def create_app(self): from celerys.tasks import celery celery.config_from_object(config["testing2"]) app = create_app("testing2") return app
def setUpClass(cls): cls.app = create_app(TestConfig) cls.app.app_context().push() cls.db = db
# -*- coding:utf-8 -*- import os from apps import create_app from flask_script import Manager from flask_migrate import MigrateCommand config_name = os.environ.get('FLASK_CONFIG') or 'default' # config_name = 'default' app = create_app(config_name) manager = Manager(app) manager.add_command('db',MigrateCommand) if __name__ == '__main__': manager.run()
# -*- coding: utf-8 -*- import apps import config app = apps.create_app(config) # This is only used when running locally. When running live, gunicorn runs # the application. if __name__ == '__main__': app.run(host='192.168.50.12', port=8080, debug=True)
# -*-coding:utf8-*- from apps import create_app from conf import conf app = create_app() # 获取flask实例 if __name__ == '__main__': # 启动服务;是否开启调试模式、监听IP和端口在conf.py里设置 app.run(debug=conf.DEBUG, port=conf.PORT, host=conf.HOST)
# Python from os import getenv from os.path import dirname, isfile, join # Third from dotenv import load_dotenv # Apps _ENV_FILE = join(dirname(__file__), ".env") if isfile(_ENV_FILE): load_dotenv(dotenv_path=_ENV_FILE) from apps import create_app, celery from apps.celery_utils import init_celery app = create_app(getenv("FLASK_ENV") or "default") init_celery(celery, app)
#!/usr/bin/python import os # virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/' virtenv = os.path.join(os.getenv('OPENSHIFT_PYTHON_DIR', '.'), 'virtenv') virtualenv = os.path.join(virtenv, 'bin/activate_this.py') try: execfile(virtualenv, dict(__file__=virtualenv)) except IOError: pass # # IMPORTANT: Put any additional includes below this line. If placed above this # line, it's possible required libraries won't be in your searchable path # from apps import create_app application = create_app() # # Below for testing only # if __name__ == '__main__': if os.getenv('LOCAL', False): application.run() else: from wsgiref.simple_server import make_server httpd = make_server('localhost', 8051, application) # Wait for a single request, serve it and quit. httpd.serve_forever()
from flask_script import Manager, Shell, Server from flask_migrate import Migrate, MigrateCommand from flask_login import login_required from apps import create_app, db from apps.models import User app = create_app('development') manager = Manager(app) migrate = Migrate(app, db) server = Server(host="0.0.0.0") def make_shell_context(): return dict(app=app, db=db, user=User) manager.add_command("shell", Shell(make_context=make_shell_context)) manager.add_command("db", MigrateCommand) manager.add_command('runserver', server) @app.route('/secret') @login_required def secret(): return "only authenticated users are allowed" if __name__ == '__main__': manager.run()
from os import getenv from os.path import dirname, isfile, join from dotenv import load_dotenv _ENV_FILE = join(dirname(__file__), '.env') if isfile(_ENV_FILE): load_dotenv(dotenv_path=_ENV_FILE) from apps import create_app app = create_app(getenv('FLASK_ENV') or 'default') if __name__ == '__main__': host = 'localhost' ip = '0.0.0.0' port = app.config['APP_PORT'] debug = app.config['DEBUG'] app.run(host=host, debug=debug, port=port, use_reloader=debug)
from apps import create_app app = create_app('dev') if __name__ == '__main__': app.run()
# -*- coding: utf-8 -*- from flask_script import Manager from flask_migrate import Migrate, MigrateCommand from apps.Library import db from apps import create_app from apps.Moduel.MySQL import notice from apps.Moduel.MySQL import user app = create_app() Migrate(app, db) # 添加数据库相关命令行 manager = Manager(app) manager.add_command('db', MigrateCommand) if __name__ == '__main__': manager.run()
import datetime from threading import Lock from flask_script import Manager, Server import settings # from common import logger from apps import create_app MODEL = 'product' app = create_app(MODEL) manager = Manager(app) manager.add_command( "runserver", Server(settings.config_map[MODEL].HOST, settings.config_map[MODEL].PORT)) if __name__ == '__main__': app.run(host=settings.config_map[MODEL].SERVER_HOST, port=settings.config_map[MODEL].PORT, debug=settings.config_map[MODEL].DEBUG)
from flask_script import Manager from apps import (create_app) from src.config import app_config application = create_app(app_config) manager = Manager(application) @manager.command def runserver(): application.run(host='0.0.0.0', port='8080', debug=True) if __name__ == '__main__': manager.run()
# -*- coding: utf-8 -*- #import queue from multiprocessing import Queue from flask import jsonify, g # from apps import create_app import apps from apps.Log.LogToDB import LogToDB from apps.utils.functions import getGUID app = apps.create_app() @app.route('/') def show(): return 'hello world', 200 @app.before_request def before_request(*args, **kwargs): g.LogQueue = Queue() g.LogGuid = getGUID() LogToDB(g.LogQueue, g.LogGuid) app.logger.info('Started') @app.after_request def after_request(response): """ Logging after every request. """ # This avoids the duplication of registry in the log,
# -*- coding: utf-8 -*- # from gevent import monkey; monkey.patch_all() import logging.handlers from abc import ABC from flask_script import Manager from flask_migrate import Migrate, MigrateCommand # from gunicorn.app.base import BaseApplication # from gunicorn.six import iteritems from multiprocessing import cpu_count from apps import create_app, db from config import config # from apps.models import db app = create_app(config) manager = Manager(app) migrate = Migrate(app, db) manager.add_command('db', MigrateCommand) # class StandaloneApplication(BaseApplication, ABC): # """ # gunicorn服务器启动类 # """ # # def __init__(self, application, options): # self.application = application # self.options = options or {} # super(StandaloneApplication, self).__init__() # # def load_config(self):
# -*- coding: utf-8 -*- from apps import create_app application = create_app() if __name__ == '__main__': ip = '0.0.0.0' port = application.config['APP_PORT'] debug = application.config['DEBUG'] application.run(host=ip, debug=debug, port=port, threaded=True, use_reloader=debug)
from flask import Flask from apps import create_app from flask_script import Manager, Server from flask_migrate import MigrateCommand manage = Manager(app=create_app()) manage.add_command('run', Server(host='127.0.0.1', port=8080, threaded=True)) manage.add_command('db', MigrateCommand) if __name__ == '__main__': manage.run()
def create_app(self): from apps import create_app return create_app()
from flask_migrate import Migrate, MigrateCommand from flask_script import Manager from apps import create_app from apps.ext import db from apps.user.model import * from apps.loan.model import * app = create_app() # 创建flask app manager = Manager(app=app) # 命令管理app # 配置 migrate 数据库命令管理工具关联 既影响app 又能让manager进行命令管理 migrate = Migrate(app=app, db=db) # 关联app 操作数据库 manager.add_command('db', MigrateCommand) # 命令交给manager管理 @manager.command def init(): # 自定义启动命令 print('manager defined app init command') if __name__ == '__main__': manager.run()
import os from apps import celery, create_app #app = create_app(os.getenv('FLASK_CONFIG') or 'default') app = create_app('default') app.app_context().push()
except ImportError: coverage = COV = None if os.path.exists('.env'): print('Importing environment from .env...') for line in open('.env'): var = line.strip().split('=') if len(var) == 2: os.environ[var[0]] = var[1] from flask.ext.script import Manager, Shell from flask.ext.migrate import Migrate, MigrateCommand from apps import create_app, db app = create_app(os.getenv('FLASK_CONFIG') or 'default') # This import must be put behind app initialization to avoid TypeError because # `register_blueprints` function uses app logger which requires app to be # created first. from apps.common.utils.initialize import load_models, register_blueprints # NOQA manager = Manager(app) migrate = Migrate(app, db) def make_shell_context(): return dict(app=app, db=db) manager.add_command("shell", Shell(make_context=make_shell_context))
def __init__(self, enforce_csrf_checks=True, *args, **kwargs): self.enforce_csrf_checks = enforce_csrf_checks from apps import create_app self.app = create_app()
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() db.create_all()
#!/usr/bin/env python # -*- coding: utf-8 -*- import os import sys import logging from logging.handlers import TimedRotatingFileHandler from flask import jsonify from flask_script import Manager, Shell, Server from apps import create_app from apps.exception import TTException FLASK_CONFIG = os.getenv("FLASK_CONFIG", "default") app = create_app(FLASK_CONFIG) # logger config handler = TimedRotatingFileHandler(app.config['APP_LOG_FILE'], when='D', backupCount=15) handler.setLevel(logging.DEBUG) formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s') handler.setFormatter(formatter) app.logger.addHandler(handler) @app.errorhandler(TTException) def handle_http_exception(error): """细化处理请求错误,返回响应 :param error: HTTPException instance :return: response """
from vibora.tests import TestSuite from apps import create_app app = create_app('testing') class HomeTestCase(TestSuite): def setUp(self): self.client = app.test_client() async def test_home(self): response = await self.client.get('/v1/home') self.assertEqual(response.content, b'{"hello":"world"}')
import os from apps import db, migrate, create_app from apps.ocr.models import ( ClientBaseConfigure, UserInfor, PicInfor, PdfInfor, ) env = os.environ.get('WEBAPP_ENV', 'dev') app = create_app('config.%sConfig' % env.capitalize()) @app.shell_context_processor def make_shell_context(): return dict( app=app, db=db, ClientConfig=ClientBaseConfigure, User=UserInfor, PicInfor=PicInfor, PdfInfor=PdfInfor, migrate=migrate, )
@desc: @author: @contact: @file:manage.py @time:2020/8/24 16:08; """ from flask_script import Manager from apps import create_app from flask_migrate import MigrateCommand from apps.models import Posts from apps.models import User from apps.exts import db import time app = create_app('default') manager = Manager(app) manager.add_command('db',MigrateCommand) @manager.command def create_test_post(): # 内容 作者 for x in range(1,200): content = '内容:%s' % x author = User.query.first() post = Posts(content=content,author=author) time.sleep(0.2) db.session.add(post) db.session.commit()
from apps import create_app app = create_app(config_name="default") if __name__ == "__main__": app.run()
# !/usr/bin/env python # coding:utf-8 # author bai from flask_script import Manager from apps import create_app app = create_app() manage = Manager(app) if __name__ == '__main__': app.run(debug=False)
#python uploads.py runserver -p 80 #!/usr/bin/env python from flask_script import Manager,prompt_bool from apps import create_app from apps.utils import story as story app = create_app( 'dev' ) manager = Manager(app) ''' from flask_migrate import Migrate,MigrateCommand from apps import db,create_app from apps.models import User,Bookmark ,Tag,Post,Role,Follow #app = create_app(os.getenv('ATLAS_ENV') or 'dev' ) migrate = Migrate(app,db) manager.add_command('db',MigrateCommand) @manager.command def insert_data(): couchk = User(username="******", email="*****@*****.**", password="******") db.session.add(couchk) def add_bookmark(url, description, tags): db.session.add(Bookmark(url=url, description=description, user_id=couchk.id, tags=tags))