def main(): check_django_installed() delete_previous_app() create_app() build_template_folders() create_urls() create_views()
def setUp(self) -> None: self.app = create_app("testing") self.client = self.app.test_client() self.app.app_context().push() db.create_all() self.book_data = json.dumps({ "title": "Single Book", "author": "Book author", "price": 200 }) self.headers = {"Content-Type": "application/json"}
"""Module for managing application""" import os from getpass import getpass import re from flask_migrate import MigrateCommand from flask_script import Manager from sqlalchemy.exc import IntegrityError from auth.models import User from utils import create_app, db from config import EMAIL_REGEX, USERNAME_REGEX app = create_app(os.getenv('FLASK_ENV') or 'default') manager = Manager(app) manager.add_command('db', MigrateCommand) @manager.command def create_admin(): """Create user with admin rights""" username = input("Enter username: "******"Invalid username!" email = input("Enter email: ") if not re.search(EMAIL_REGEX, email): return "Invalid email!" for _ in range(3): password = getpass("Enter password: ")
import uuid import json import os import sys import zmq as ZMQ from flask import Flask, request, send_file from flask_restplus import Resource, Api, Namespace, reqparse from werkzeug.datastructures import FileStorage from utils import create_app env = os.environ.get("APP_ENV", "Development") #assume dev env by default print(env) app, api, zmq = create_app(env) @api.route('/resize/') class ImageResize(Resource): upload_parser = reqparse.RequestParser() upload_parser.add_argument('file', type=FileStorage, location='files', required=False) @api.expect(upload_parser) def post(self): guid = str(uuid.uuid4()) # get the file and save it to our location file = request.files['file']
from flask import render_template, session, g import config import utils from login import models as login_models app = utils.create_app(config) @app.before_request def load_user(): if 'user_id' in session: g.user = login_models.User.query.get(session["user_id"]) if not g.user: session.pop('user_id') else: g.user = None @app.route('/') @utils.login_required def index(): return render_template('index.html') if __name__ == '__main__': app.run()
import utils app = utils.create_app() @app.route('/') def index(): return 'Hello 2 world' if __name__ == '__main__': app.run(threaded=True, host='0.0.0.0', port=5000)
"""__author__= 雍新有""" from flask_script import Manager from utils import create_app # 获取flask对象app app = create_app() if __name__ == '__main__': manage = Manager(app) manage.run()
#!/usr/bin/env python3 from sanic import response from sanic.exceptions import abort from utils import create_app, run_server, forward_request app, libtoken, license, index_html = create_app() @app.route("/") async def index(request): return response.html(index_html) @app.route('/favicon.ico') async def favicon(request): abort(404) @app.route('/<path:[^/].*?>') async def forward(request, path): return await forward_request(request, path, libtoken, license) if __name__ == '__main__': run_server(app, '0.0.0.0', 8000, False)
from http import HTTPStatus from flask import abort, jsonify, Response from report import get, create from generator import tasks from utils import Fmts, create_app, make_celery app = create_app(__name__) celery = make_celery(app) @app.route('/') def index(): return 'Hello world' @app.route('/reports/<string:_id>/', methods=['GET']) def read_report(_id: str): fmt, data = get(_id) if fmt == Fmts.xlsx: if not data: abort(HTTPStatus.NOT_ACCEPTABLE, f'Not ready') return Response(data.stream(32 * 1024), headers=dict(data.headers), direct_passthrough=True) elif fmt == Fmts.json: return jsonify(data) abort(HTTPStatus.BAD_REQUEST, f'Unknown fmt: `{fmt}`')
import os from utils import create_app, celery app = create_app(os.getenv('FLASK_CONFIG') or 'default') app.app_context().push()