Exemple #1
0
def create_app(config):
    app = ApiFlask(__name__, static_folder=config.STATIC_FOLDER)
    app.config.from_object(config)

    db.init_app(app)
    swagger.init_app(app)
    sentry.init_app(app)

    app.register_blueprint(api_bp)
    app.register_blueprint(admin_bp)

    return app
Exemple #2
0
class ErrorHandler(_ErrorHandler):
    def default(self, request, exception):
        exc = '\n'.join(traceback.format_tb(sys.exc_info()[-1]))
        if 'Connection refused' in str(exception) and 'memcache' in exc:
            exception = ServerError(
                f'Please confirm that memcached is running!\n{exc}')
        return super().default(request, exception)


app = Sanic(__name__, request_class=Request)
app.error_handler = ErrorHandler()
app.config.from_object(config)
mako.init_app(app, context_processors=())
if sentry is not None:
    sentry.init_app(app)
register_blueprints('views', app)
try:
    register_blueprints('custom', app)
except ImportStringError:
    ...
app.static('/static', './static')

session = Session()
client = None
redis = None


@app.exception(NotFound)
async def ignore_404s(request, exception):
    return text("Oops, That page couldn't found.")