def app(request): app = Flask(__name__) app.debug = True app.config['SECRET_KEY'] = 'secret' app.config['TESTING'] = True app.config['BITMAPIST_REDIS_URL'] = 'redis://localhost:6379' app.config['SECRET_KEY'] = 'verysecret' return app
def create_app(): import os app = Flask(__name__) app.config['SECRET_KEY'] = os.urandom(40) @app.route('/an-error/', methods=['GET', 'POST']) def an_error(): raise ValueError('hello world') @app.route('/capture/', methods=['GET', 'POST']) def capture_exception(): try: raise ValueError('Boom') except: current_app.extensions['sentry'].captureException() return 'Hello' @app.route('/message/', methods=['GET', 'POST']) def capture_message(): current_app.extensions['sentry'].captureMessage('Interesting') return 'World' @app.route('/an-error-logged-in/', methods=['GET', 'POST']) def login(): login_user(User()) raise ValueError('hello world') return app
def setUp(self): app = Flask(__name__) app.config['SECRET_KEY'] = 'my secret' digest_auth_my_realm = HTTPDigestAuth(realm='My Realm') @digest_auth_my_realm.get_password def get_digest_password_3(username): if username == 'susan': return 'hello' elif username == 'john': return 'bye' else: return None @app.route('/') def index(): return 'index' @app.route('/digest-with-realm') @digest_auth_my_realm.login_required def digest_auth_my_realm_route(): return 'digest_auth_my_realm:' + digest_auth_my_realm.username() self.app = app self.client = app.test_client()
def create_app(ignore_exceptions=None, debug=False, **config): import os app = Flask(__name__) app.config['SECRET_KEY'] = os.urandom(40) for key, value in config.items(): app.config[key] = value app.debug = debug if ignore_exceptions: app.config['RAVEN_IGNORE_EXCEPTIONS'] = ignore_exceptions @app.route('/an-error/', methods=['GET', 'POST']) def an_error(): raise ValueError('hello world') @app.route('/capture/', methods=['GET', 'POST']) def capture_exception(): try: raise ValueError('Boom') except: current_app.extensions['sentry'].captureException() return 'Hello' @app.route('/message/', methods=['GET', 'POST']) def capture_message(): current_app.extensions['sentry'].captureMessage('Interesting') return 'World' @app.route('/login/', methods=['GET', 'POST']) def login(): login_user(User()) return "hello world" return app
def create_app(configfile=None): app = Flask(__name__) # AppConfig(app, configfile) # Flask-Appconfig is not necessary, but # highly recommend =) # https://github.com/mbr/flask-appconfig Bootstrap(app) # in a real app, these should be configured through Flask-Appconfig app.config['SECRET_KEY'] = 'devkeyqwerasdf' #app.config['RECAPTCHA_PUBLIC_KEY'] = '6Lfol9cSAAAAADAkodaYl9wvQCwBMr3qGR_PPHcw' @app.route('/', methods=('GET', 'POST')) def index(): if request.method == 'POST': question = request.form['question'] print(question) answer = inquire.answer_question(question) return render_template('answer.html', answer=answer) form = ExampleForm() return render_template('index.html', form=form) # @app.route('/answer') # def answer(): # form return app
def create_app(): app = Flask(__name__, static_folder=os.path.join(PROJECT_ROOT, 'public'), static_url_path='/public') app.config.update(os.environ) #TODO: read in right hand side from HT config vars app.config['SECRET_KEY'] = 'secret' app.config['SECURITY_PASSWORD_HASH'] = 'bcrypt' app.config['MONGODB_DB'] = 'flask_security_test' app.config['MONGODB_HOST'] = 'localhost' app.config['MONGODB_PORT'] = 27017 app.debug = app.config['X_HT_DEBUG'] == "True" app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {'/': os.path.join(os.path.dirname(__file__), 'public') }) @app.errorhandler(404) def page_not_found(e): return render_template('404.html'), 404 SecuritySetup(app) # import & register blueprints here: #=================================== from hero_tmpl.views.security import security app.register_blueprint(security) from hero_tmpl.views.misc import misc app.register_blueprint(misc) return app
def create_app(self): app = Flask(__name__) app.config['TESTING'] = True app.config['SECRET_KEY'] = 'secret secret' app.config['IMAGES_PATH'] = ['assets'] self.images = Images(app) return app
def create_app(app_mode='DEBUG'): """ Create application, register blueprints, etc """ if app_mode == '': app_mode = os.environ.get('APP_MODE', 'DEBUG') # create an application app = Flask(__name__) app.config['SECRET_KEY'] = b'\x88~\x17h\xdc;,\x9f\x1do\x98\xcd\xaf|\x1c\x19\xec\xcf\xb1\x12\xd4\x8b\xcdQ' # set logging configure_logging(app_mode, app) if app_mode == 'DEBUG': # debugging in VSCode works only if following 2 lines are commented out #app.debug = True #app.config['DEBUG'] = True app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0 # register blueprints app.register_blueprint(public_ui) app.register_blueprint(member_ui) app.register_blueprint(customer_ui) # register jinja exts app.add_template_filter(f=points, name='points') # configure uploads app.config['UPLOAD_FOLDER'] = os.path.join(BASE_DIR, 'uploads') # app started logging.info('Application started in %s mode', app_mode) return app
def create_app(environ): app = Flask(__name__, static_url_path='/brigade/static') app.config['SECRET_KEY'] = 'sekrit!' app.register_blueprint(brigade) app.register_blueprint(filters) return app
def generate_app(): app = Flask(__name__) app.config['PROPAGATE_EXCEPTIONS'] = True app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DB_URI'] with open("/data/secret_key") as fd: app.config['SECRET_KEY'] = fd.read().strip() return app
def create_app(configfile=None): app = Flask(__name__) AppConfig(app, configfile) # Flask-Appconfig is not necessary, but # highly recommend =) # https://github.com/mbr/flask-appconfig Bootstrap(app) # in a real app, these should be configured through Flask-Appconfig app.config['SECRET_KEY'] = 'devkey' app.config['RECAPTCHA_PUBLIC_KEY'] = \ '6Lfol9cSAAAAADAkodaYl9wvQCwBMr3qGR_PPHcw' @app.route('/garage') def add_numbers(): ajax_request = request.args.get('ajax_request', 0, type=str) print "wassup!\nwassup!\nwassup!\nwassup!\nwassup!\nwassup!\nwassup!\n" #open_garage() return jsonify(result=ajax_request) @app.route('/', methods=('GET', 'POST')) def index(): #form = ExampleForm() #form.validate_on_submit() # to get error messages to the browser #flash('critical message', 'critical') #flash('error message', 'error') #flash('info message', 'info') #flash('debug message', 'debug') #flash('different message', 'different') #flash('uncategorized message') flash('This application is undergoing tests', 'warning') #return render_template('index.html', form=form) return render_template('index.html') return app
def setup(): app = Flask(__name__) app.config['SECRET_KEY'] = '1' app.config['CSRF_ENABLED'] = False admin = Admin(app) return app, admin
def create_app(configfile=None): app = Flask(__name__) AppConfig(app, configfile) # Flask-Appconfig is not necessary, but # highly recommend =) # https://github.com/mbr/flask-appconfig Bootstrap(app) # in a real app, these should be configured through Flask-Appconfig app.config['SECRET_KEY'] = 'devkey' app.config['RECAPTCHA_PUBLIC_KEY'] = \ '6Lfol9cSAAAAADAkodaYl9wvQCwBMr3qGR_PPHcw' @app.route('/', methods=('GET', 'POST')) def index(): form = ExampleForm() form.validate_on_submit() # to get error messages to the browser flash('critical message', 'critical') flash('error message', 'error') flash('warning message', 'warning') flash('info message', 'info') flash('debug message', 'debug') flash('different message', 'different') flash('uncategorized message') return render_template('index.html', form=form) return app
def create_app(self): """Create a new instance of sipa using :py:func:`create_app` A new instance of sipa will be executed with the following config customizations: - SECRET_KEY is set to a random value - TESTING is set to True - debug is enabled - WTF_CSRF_ENABLED is set to False - PRESERVE_CONTEXT_ON_EXCEPTION This config is extended by the values of the attribute :py:attr:`app_config`. """ test_app = Flask('sipa') test_app.config['SECRET_KEY'] = os.urandom(100) test_app.config['TESTING'] = True test_app.config['LOG_CONFIG'] = WARNINGS_ONLY_CONFIG test_app.config['WTF_CSRF_ENABLED'] = False test_app.config['PRESERVE_CONTEXT_ON_EXCEPTION'] = False test_app.config['CONTACT_SENDER_MAIL'] = "test@foo.de" test_app.debug = True return create_app(app=test_app, config=self.app_config)
def create_app(config=None): app = Flask(__name__) app.config['SECRET_KEY'] = '129iv3n91283nv9812n3v89q2nnv9iaszv978n98qwe7z897d' app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://postgres@localhost/mooddiaryDb' #app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/mooddiary.db' app.config['DEBUG'] = True app.config['ASSETS_DEBUG'] = True app.config['LESS_BIN'] = os.path.realpath(os.path.join(os.path.dirname(__file__), '../node_modules/less/bin/lessc')) app.config['JWT_EXPIRATION_DELTA'] = timedelta(days=28) app.config['JWT_ALGORITHM'] = 'HS512' app.config['RECAPTCHA_SECRET_KEY'] = '6LdSswwTAAAAADs20eK6NqYaeppxIWm-gJrpto0l' app.config['RECAPTCHA_PUBLIC_KEY'] = '6LdSswwTAAAAABTZq5Za_0blmaSpcg-dFcqaGda9' if config: app.config.from_object(config) db.init_app(app) migrate.init_app(app, db) assets.init_app(app) jwt.init_app(app) assets.register('js', js) assets.register('css', css) app.register_blueprint(main) app.register_blueprint(api, url_prefix='/api') app.register_blueprint(auth, url_prefix='/auth') return app
def app(jwt, user): app = Flask(__name__) app.debug = True app.config['SECRET_KEY'] = 'super-secret' app.config['JWT_EXPIRATION_DELTA'] = timedelta(milliseconds=200) jwt.init_app(app) @jwt.authentication_handler def authenticate(username, password): if username == user.username and password == user.password: return user return None @jwt.user_handler def load_user(payload): if payload['user_id'] == user.id: return user @app.route('/protected') @flask_jwt.jwt_required() def protected(): return 'success' return app
def create_app(config_name): app = Flask(__name__) app.config['SECRET_KEY'] = 'zxl' Bootstrap(app) app.register_blueprint(index.mod) app.register_blueprint(api.mod, url_prefix='/api') return app
def create_app(): options = { 'port' : 0, 'unitTesting': False } WebConfig.config(options) b = Borg() app = Flask(__name__) app.config['DEBUG'] = True app.config['SECRET_KEY'] = b.secretKey app.config['SECURITY_PASSWORD_HASH'] = b.passwordHash app.config['SECURITY_PASSWORD_SALT'] = b.passwordSalt app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://' + b.auth_dbUser + ':' + b.auth_dbPasswd + '@' + b.auth_dbHost + '/' + b.auth_dbName b.logger.setLevel(b.logLevel) b.logger.debug('Error handlers: {0}'.format(app.error_handler_spec)) app.secret_key = os.urandom(24) logger = logging.getLogger('werkzeug') logger.setLevel(b.logLevel) enable_debug = b.logLevel = logging.DEBUG cors = CORS(app) db.init_app(app) user_datastore = SQLAlchemyUserDatastore(db,User, Role) security = Security(app, user_datastore) from main import main as main_blueprint app.register_blueprint(main_blueprint) with app.app_context(): db.create_all() return app
def create_app(): app = Flask(__name__) app.config['SECRET_KEY'] = SECRET_KEY Bootstrap(app) @app.route('/', methods=('GET', 'POST')) def index(): if request.method == 'POST': question = request.form['question'] qtype, qcut, kwords = answer_question(question) # 保存用户的问题及判断到的类型 save_userask(qtype, question, qcut) return render_template( 'answer.html', qtype=qtype, qcut=" ".join(qcut), kwords=kwords, question=question) return render_template('index.html', form=QuestionForm()) # API @app.route('/api/classify', methods=('GET', 'POST')) def api_classify(): if request.method == 'POST': question = request.values.get('q', None) qtype, qcut, kwords = answer_question(question) save_userask(qtype, question, qcut) return json.dumps({'error': '0', 'question': question, 'qtype': qtype}) return json.dumps({'error': '405', 'message': 'wrong request method'}) return app
def start_server(args): app = Flask(__name__) app.config['SECRET_KEY'] = 'secret' app.jinja_env.globals['static'] = static blueprint.url_prefix = args.url_prefix app.register_blueprint(blueprint) # app.run(port=args.port, debug=args.debug) wsgi_app = tornado.wsgi.WSGIContainer(app) condajs_ws = sockjs.tornado.SockJSRouter(views.CondaJsWebSocketRouter, '/condajs_ws') routes = condajs_ws.urls routes.append((r".*", tornado.web.FallbackHandler, dict(fallback=wsgi_app))) application = tornado.web.Application(routes, debug=args.debug) try: application.listen(args.port) except OSError as e: print("There was an error starting the server:") print(e) return ioloop = tornado.ioloop.IOLoop.instance() if not args.debug: callback = lambda: webbrowser.open_new_tab('http://localhost:%s' % args.port) ioloop.add_callback(callback) ioloop.start()
def app(urs, user): app = Flask(__name__) app.debug = True app.config['SECRET_KEY'] = 'super-secret' app.config['JWT_EXPIRATION_DELTA'] = timedelta(milliseconds=600) app.config['JWT_EXPIRATION_LEEWAY'] = timedelta(milliseconds=5) urs.init_app(app) @app.route('/protected') @flask_urs.jwt_required() def protected(): return 'success' @app.route("/authorize") def authorize(): return jsonify({ "access_token": "asdf", "refresh_token": "asdf", "endpoint": "/endpoint" }) @app.route("/endpoint") def endpoint(): return jsonify(user) # Establish an application context before running the tests. ctx = app.app_context() ctx.push() def teardown(): ctx.pop() return app
def setUp(self): app = Flask(__name__) app.config['SECRET_KEY'] = 'my secret' basic_verify_auth = HTTPBasicAuth() @basic_verify_auth.verify_password def basic_verify_auth_verify_password(username, password): g.anon = False if username == 'john': return password == 'hello' elif username == 'susan': return password == 'bye' elif username == '': g.anon = True return True return False @basic_verify_auth.error_handler def error_handler(): return 'error', 403 # use a custom error status @app.route('/') def index(): return 'index' @app.route('/basic-verify') @basic_verify_auth.login_required def basic_verify_auth_route(): return 'basic_verify_auth:' + basic_verify_auth.username() + \ ' anon:' + str(g.anon) self.app = app self.basic_verify_auth = basic_verify_auth self.client = app.test_client()
def create_app(config_name): app = Flask(__name__) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://' app.config.from_object(config[config_name]) app.config['SECRET_KEY'] = 'you-will-never-guess' config[config_name].init_app(app) bootstrap.init_app(app) db.init_app(app) login_manager.init_app(app) from .auth import auth as auth_blueprint app.register_blueprint(auth_blueprint) from .main import main as main_blueprint app.register_blueprint(main_blueprint) from .admin import admin as admin_blueprint app.register_blueprint(admin_blueprint, url_prefix='/departments') from .issues import issues as issues_blueprint app.register_blueprint(issues_blueprint, url_prefix='/issues') @app.errorhandler(404) def not_found(error): return render_template('404.html', title="404 Error"), 404 @app.errorhandler(403) def forbidden(error): return render_template('403.html', title="403 Error"), 403 # with app.app_context(): # db.create_all() return app
def create_app(self): app = Flask(__name__) app.config['TESTING'] = True app.config['SERVER_NAME'] = 'localhost' app.config['SECRET_KEY'] = 'secret secret' app.config['IMAGINE_ADAPTER'] = { 'name': 'fs', } app.config['IMAGINE_FILTER_SETS'] = { 'test_scale_cached': { 'cached': True, 'filters': { 'thumbnail': {'size': [100, 100], 'mode': 'inset'} } }, 'test_scale_dynamic': { 'cached': False, 'filters': { 'thumbnail': {'size': [100, 100], 'mode': 'inset'} } } } self.imagine = Imagine(app) return app
def create_app(): app = Flask(__name__) register_blueprints(app) register_extensions(app) register_jinja_funcs(app) # Create modules # the debug toolbar is only enabled in debug mode app.config['DEBUG'] = True app.config['ADMINS'] = frozenset(['youremail@yourdomain.com']) app.config['SECRET_KEY'] = 'SecretKeyForSessionSigning' app.config['DATABASE_CONNECT_OPTIONS'] = {} app.config['THREADS_PER_PAGE'] = 8 app.config['CSRF_ENABLED'] = True app.config['CSRF_SESSION_KEY'] = 'somethingimpossibletoguess' # Enable the toolbar? app.config['DEBUG_TB_ENABLED'] = app.debug # Should intercept redirects? app.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = True # Enable the profiler on all requests, default to false app.config['DEBUG_TB_PROFILER_ENABLED'] = True # Enable the template editor, default to false app.config['DEBUG_TB_TEMPLATE_EDITOR_ENABLED'] = True # debug toolbar # toolbar = DebugToolbarExtension(app) return app
def create_app(debug=False): app = Flask(__name__) app.debug = debug app.config['SECRET_KEY'] = 'secret' @app.route('/') def index(): doc = BootstrapDocument() # add socket-io client to the doc and our custom js. doc.scripts.add(script( src='//cdn.socket.io/socket.io-1.4.5.js', type='text/javascript'), script(src='/static/my.js', type='text/javascript')) doc.body.children.insert(0, Div(h1('Advanced Example'), Div(h3('Flashes'), Div(id='flashes')))) # add buttons below the content of the document doc.body.add(Button( 'Table', onclick="user_socket.emit('table');"), Button('Form', onclick="user_socket.emit('form');")) return doc.render() io.init_app(app) user_io.init_io(io) return app
def create_app(config, debug=True): app = Flask(__name__) app.debug = debug app.config['SECRET_KEY'] = 'secret' app.config['SECURITY_POST_LOGIN_VIEW'] = '/profile' from tests.test_app.config import Config app.config.from_object(Config) if config: for key, value in config.items(): app.config[key] = value app.wsgi_app = HTTPMethodOverrideMiddleware(app.wsgi_app) @app.route('/') def index(): return render_template('index.html', content='Home Page') @app.route('/profile') @login_required def profile(): twitter = current_app.social.twitter twitter.get_api() return render_template( 'profile.html', content='Profile Page', twitter_conn=twitter.get_connection(), google_conn=current_app.social.google.get_connection(), facebook_conn=current_app.social.facebook.get_connection(), foursquare_conn=current_app.social.foursquare.get_connection()) return app
def create_app(): app = Flask(__name__) app.config['SECRET_KEY'] = os.environ.get("FLASK_SECRET_KEY", "abcdef") db.init_app(app) with app.test_request_context(): db.create_all() return app
def create_app(): setup_config(sys.argv[1], 'dnsdb-updater', conf_dir=os.path.dirname(os.path.dirname(__file__))) log.error('This host belong to host group %s' % CONF.host_group) app = Flask(__name__) app.config['SECRET_KEY'] = CONF.etc.secret_key from dns_updater.utils.updater_util import check_necessary_options check_necessary_options() @app.route("/healthcheck.html", methods=['GET']) def health_check(): try: return render_template('healthcheck.html') except TemplateNotFound: abort(404) @app.context_processor def default_context_processor(): result = {'config': {'BASE_URL': CONF.web.base_url}} return result from dns_updater import api app.register_blueprint(api.bp, url_prefix='/api') return app
def setUp(self): app = Flask(__name__) app.config['SECRET_KEY'] = 'my secret' digest_auth_ha1_pw = HTTPDigestAuth(use_ha1_pw=True) @digest_auth_ha1_pw.get_password def get_digest_password(username): if username == 'susan': return get_ha1(username, 'hello', digest_auth_ha1_pw.realm) elif username == 'john': return get_ha1(username, 'bye', digest_auth_ha1_pw.realm) else: return None @app.route('/') def index(): return 'index' @app.route('/digest_ha1_pw') @digest_auth_ha1_pw.login_required def digest_auth_ha1_pw_route(): return 'digest_auth_ha1_pw:' + digest_auth_ha1_pw.username() self.app = app self.client = app.test_client()