def create_app(object_name):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. {{cookiecutter.repo_name}}.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    doc = ApiDoc(app=app,url_path='/apidoc')

    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    db.init_app(app)

    login_manager.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    # register our blueprints
    app.register_blueprint(main)

    return app
Esempio n. 2
0
from dotenv import load_dotenv
load_dotenv()
import os
from flask import Flask, render_template, jsonify
import requests
from flask_apidoc import ApiDoc

app = Flask(__name__)
doc = ApiDoc(app=app)
"""
@api {get} / landing page
@apiName landing page
@apiGroup all

@apiSuccess {boolean} status true/false

@apiParamExample {json} response-example
{
    "status":true
}
"""


@app.route("/", methods=["GET"])
def index():
    return jsonify({"status": True})


"""
@api {GET} /weather/{place} India weather info
@apiName India weather info
Esempio n. 3
0
from flask_io import FlaskIO
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from dictalchemy import DictableModel
from sqlalchemy.ext.declarative import declarative_base
from flask_apidoc import ApiDoc

Base = declarative_base(cls=DictableModel)
db = SQLAlchemy()
io = FlaskIO()
doc = ApiDoc()
login_manager = LoginManager()
Esempio n. 4
0
from flask_restful import Api
from flask_apidoc import ApiDoc
import json
import decimal

rest_api = Api()
api_doc = ApiDoc()


class DecimalEncoder(json.JSONEncoder):
    """重新定义json解析"""
    def default(self, o):
        if isinstance(o, decimal.Decimal):
            return float(o)
        elif isinstance(o, bytes):
            return o.decode(encoding='utf-8')
        return super(DecimalEncoder, self).default(o)
    
# from flask_mongoengine import MongoEngine
from flask_security.core import UserMixin, AnonymousUser
import config
from db import user_datastore
from utils import db_utils, admin_utils
from flask_admin import Admin
from modules import mod_lugar, mod_computadora, Session, MQTT
from api import mod_api
import json
from utils import render_utils
from models import Detalle_registro, Registro, Lugar, Computadora

app = config.app
db_sql = config.db_sql

doc = ApiDoc(app=app, url_path='/api/docs', dynamic_url=False)


# Create a user to test with
@app.before_first_request
def create_db():
    db_utils.create_sample_db(db_sql, user_datastore)
    MQTT()


# Initialize Flask-Admin
admin = Admin(app, template_mode='bootstrap3', url='/admin')

admin_utils.load_model_views(admin, db_sql)

qrcode = QRcode(app)
Esempio n. 6
0
# from threading import Timer

import mongoengine
from flask_script import Manager
from flask_apidoc import ApiDoc
from flask_apidoc.commands import GenerateApiDoc
# from apscheduler.schedulers.background import BackgroundScheduler

from {{cookiecutter.project_slug}} import app, settings
from {{cookiecutter.project_slug}}.api import v1  # noqa: F401

mongoengine.connect(settings.DB_NAME,
                    host=settings.DB_HOST,
                    port=settings.DB_PORT)

ApiDoc(app=app,
       url_path='/api/docs',
       folder_path='.',
       dynamic_url=False)

manager = Manager(app)
manager.add_command('apidoc',
                    GenerateApiDoc(output_path='./{{cookiecutter.project_slug}}/static'))

if __name__ == '__main__':
    manager.run()