コード例 #1
0
ファイル: __init__.py プロジェクト: quaxsze/poc-recherche
def create_app() -> Flask:
    app: Flask = Flask(__name__,
                       static_folder="../dist/static",
                       template_folder="../dist")

    # CORS only for local dev
    CORS(app, resources={r"/api/*": {"origins": "http://localhost:8080"}})

    app.config.from_object(Config)

    app.elasticsearch = Elasticsearch([
        app.config["ELASTICSEARCH_URL"]
    ]) if app.config["ELASTICSEARCH_URL"] else None

    result_list: list = download_baserow_api(
        app.config["BASEROW_ORG_BADGES_TO_BOOST_URL"])
    app.config['ORG_BADGES_TO_BOOST'] = []
    for result in result_list:
        if result['field_98434']:
            app.config['ORG_BADGES_TO_BOOST'].append(result['field_98433'])

    # register the database command
    from backend import db
    db.init_app(app)

    from backend import routes
    app.register_blueprint(routes.bp)

    return app
コード例 #2
0
ファイル: __init__.py プロジェクト: RyanConwell/kenco-pbl
def create_app(test_config=None):
    # Create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='developmentsecretisnotgoodsecret',
        DATABASE=os.path.join(app.instance_path, 'backend.sqlite'),
    )

    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

    # register the database commands
    from backend import db
    db.init_app(app)

    # apply blueprints to the app (and init mail)
    from backend import api, monitor
    app.register_blueprint(api.bp)
    app.register_blueprint(monitor.bp)
    api.mail.init_app(app)

    return app
コード例 #3
0
ファイル: __init__.py プロジェクト: iamgroot42/owca
def create_app(test_config=None):
    """Create and configure an instance of the Flask application."""
    app = Flask(__name__, instance_relative_config=True)

    app.config.from_mapping(
        # a default secret that should be overridden by instance config
        SECRET_KEY="dev")

    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.update(test_config)

    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # register the database commands
    from backend import db

    db.init_app(app)

    # apply the blueprints to the app
    from backend import course, auth, home

    app.register_blueprint(course.bp)
    app.register_blueprint(auth.bp)
    app.register_blueprint(home.bp)

    # make url_for('index') == url_for('blog.index')
    # in another app, you might define a separate main index here with
    # app.route, while giving the blog blueprint a url_prefix, but for
    # the tutorial the blog will be the main index
    app.add_url_rule("/", endpoint="index")

    return app
コード例 #4
0
def create_app(test_config=None):
    """ Flask application factory

        Load applicaiton configuration, creates Flask instance
        and attach some hook to it
        The method is called using 'flask' command line with FLASK_APP=backend as environmnt
        variable.
    """
    app = Flask(__name__)
    app.config.from_mapping(
        mongodb={},
    )

    if test_config is None:
        app.config.update(get_config())
    else:
        app.config.update(test_config)

    @app.route('/')
    def index():
        return "Welcome Paranuara Citizen API"

    @app.errorhandler(BusinessException)
    def handle_not_found(error):
        response = jsonify(error.to_dict())
        response.status_code = error.status_code
        return response

    # Register application commands
    db.init_app(app)
    doc.init_app(app)

    app.register_blueprint(people_v1, url_prefix='/v1/people')
    app.register_blueprint(companies_v1, url_prefix='/v1/companies')
    
    app.after_request(add_cors_headers)

    return app
コード例 #5
0
ファイル: app.py プロジェクト: tanjibpa/microservice-exmpl
import os
from flask import Flask, render_template, request, redirect, url_for, flash
from flask_migrate import Migrate

from backend import read_csv, db, Product

app = Flask(__name__)
app.secret_key = "secret"
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://*****:*****@localhost:5432/micro"
app.config['UPLOAD_FOLDER'] = os.path.dirname(os.path.realpath(__file__)) + '/files'

db.init_app(app)

migrate = Migrate(app, db)

@app.route('/', methods=['POST', 'GET'])
def index():
    products = Product.query.all()
    return render_template("index.html", products=products)

@app.route('/upload', methods=['POST'])
def upload_file():
    if 'file' not in request.files:
        flash("File not found")
    csv_file = request.files['file']
    csv_file.save(os.path.join(app.config['UPLOAD_FOLDER'], csv_file.filename))
    res = read_csv(os.path.join(app.config['UPLOAD_FOLDER'], csv_file.filename))
    if not res:
        flash("Unsuccessful")
    else:
        flash(res)
コード例 #6
0
def create_app():
     db.init_app(app)
     with app.app_context():
         db.create_all()
     return True