Beispiel #1
0
def create_app(cesi):
    from api.v2 import register_blueprints

    app = Flask(
        __name__,
        static_folder="ui/build",
        static_url_path="",
        template_folder="ui/build",
    )
    app.config["SQLALCHEMY_DATABASE_URI"] = cesi.database
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    app.secret_key = os.urandom(24)

    db.init_app(app)

    app.add_url_rule("/", "index", lambda: render_template("index.html"))
    app.add_url_rule(
        "/api/version",
        "version",
        lambda: jsonify(status="success", version=__version__),
    )

    @app.errorhandler(404)
    @app.errorhandler(400)
    def _(error):
        return jsonify(status="error", message=error.description), error.code

    register_blueprints(app)

    return app
Beispiel #2
0
def create_app(db_uri="postgresql://@/updatechecker"):
    app = Flask(__name__)
    app.config["SQLALCHEMY_DATABASE_URI"] = db_uri
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    app.debug = getenv("DEBUG")
    app.register_blueprint(blueprint)
    db.init_app(app)
    return app
Beispiel #3
0
 def setUp(self):
     app = Flask("tests", static_url_path="/static")
     app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True
     app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:////tmp/test_idb.db"
     db.init_app(app)
     db.app = app
     db.configure_mappers()
     db.create_all()
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
    config[config_name].init_app(app)
    db.init_app(app)
    cache.init_app(app)
    bootstrap.init_app(app)
    login_manager.init_app(app)

    from app.main import main as bp_main
    app.register_blueprint(bp_main)

    from app.authentication import auth as bp_auth
    app.register_blueprint(bp_auth)

    from app.stage import stage as bp_stage
    app.register_blueprint(bp_stage)

    return app
Beispiel #5
0
# -*- coding: utf-8 -*-
from flask import Flask, render_template, redirect, url_for, request, session, flash, g
from functools import wraps
from flask_sqlalchemy import SQLAlchemy

app = Flask(__name__)
app.secret_key = 'temporary key'
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://localhost/posts"
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True

# create db
db = SQLAlchemy(app)


def login_required(f):
    @wraps(f)
    def wrap(*args, **kwargs):
        if 'logged_in' in session:
            return f(*args, **kwargs)
        else:
            flash(u'Нэвтрэн орно уу?')
            return redirect(url_for('login'))
    return wrap


@app.route('/')
def home():
    return render_template('public_home.html')


@app.route('/user_home')
Beispiel #6
0
    "newrelic",
    "RateLimiter"
]

for a_library in libraries_to_mum:
    the_logger = logging.getLogger(a_library)
    the_logger.setLevel(logging.WARNING)
    the_logger.propagate = True

requests.packages.urllib3.disable_warnings()

app = Flask(__name__)
# app.debug = True

# database stuff
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True  # as instructed, to supress warning
app.config["SQLALCHEMY_DATABASE_URI"] = os.getenv("DATABASE_URL")
app.config["SQLALCHEMY_POOL_SIZE"] = 60
app.config['SQLALCHEMY_ECHO'] = (os.getenv("SQLALCHEMY_ECHO", False) == "True")
db = SQLAlchemy(app)

# do compression.  has to be above flask debug toolbar so it can override this.
compress_json = os.getenv("COMPRESS_DEBUG", "False")=="True"


# set up Flask-DebugToolbar
if (os.getenv("FLASK_DEBUG", False) == "True"):
    logger.info("Setting app.debug=True; Flask-DebugToolbar will display")
    compress_json = False
    app.debug = True
    app.config['DEBUG'] = True
Beispiel #7
0
#!/usr/bin/env python

import os

from flask import Flask
from flask import render_template
from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.autodoc import Autodoc
from flask.ext.misaka import Misaka

app = Flask(__name__, template_folder="../templates", static_folder="../static")
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ['DATABASE_URL']
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = "False"
app.config["PORT"] = os.environ.get("PORT", "5000")

db = SQLAlchemy(app)
auto = Autodoc(app)
md = Misaka()
md.init_app(app)

from app import views, models
Beispiel #8
0
from flask_script import Manager,Shell
from sqlalchemy import Column, String, create_engine, MetaData
from sqlalchemy import ForeignKey
from sqlalchemy.orm import sessionmaker,relationship
from sqlalchemy.ext.declarative import declarative_base
from flask import Flask, request, render_template
from api import fetchAPI
import os

basedir = os.path.abspath(os.path.dirname(__file__))  #初始化数据库
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] =\
    'sqlite:///' + os.path.join(basedir, "data.sqlite")

app.config["SQLALCHEMY_COMMIT_ON_TEARDOWN"] = True
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False  #不追踪对象修改发信号,减少内存占有

db = SQLAlchemy(app)  # db对象是SQLAlchemy类的实例,表示程序使用的数据库
manager = Manager(app) #先抄教程,不是很懂
engine = create_engine('sqlite:////temp/test.db',convert_unicode=True)
metadata = MetaData(bind=engine)


def make_shell_context(): #用shell命令主动导入特定对象,注册make_context回调函数
    return dict(app=app, db=db, Role=Role, Weatherapi=Weatherapi)
manager.add_command("shell", Shell(make_context=make_shell_context))



class Weatherapi(db.Model):#weatherapi表定义为模型 Weatherapi
    __tablename__ = 'weatherapi'
import pickle

from flask import Flask, request
from flask_sqlalchemy import SQLAlchemy

# EB looks for an 'application' callable by default
application = Flask(__name__)
application.config[
    "SQLALCHEMY_DATABASE_URI"
] = "mysql://milkshakeiii:password@aa9h1ykact4edj.comeuynrtwyg.us-west-2.rds.amazonaws.com:3306/ebdb"
application.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(application)

from game_functions import *
from models import *
from messages import *


@application.route("/")
def index():
    # bits of text for the page
    header_text = """<html>\n<head><title>milkshakeiii's api</title></head>\n<body>"""
    footer_text = "</body>\n</html>"
    return header_text + get_index_text() + footer_text


@application.route("/queue", methods=["POST"])
def queue():
    queue_request_object = pickle.loads(request.data)
    response = handle_queue(queue_request_object)
import os
from flask import Flask, request, redirect, url_for
from flask import render_template
from crud import post_all, post_look, post_new, post_update, post_delete

blog = Flask(__name__)
blog.config.from_object(os.environ["APP_SETTINGS"])
blog.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
from database import db_session


@blog.route("/", methods=["GET"])
def index():
    posts = post_all(db_session)
    return render_template("index.html", posts=posts)


@blog.route("/<id>", methods=["GET"])
def look(id):
    post = post_look(db_session, id)
    return render_template("post.html", post=post)


@blog.route("/new")
def page_for_new_post():
    return render_template("new-post.html")


@blog.route("/add", methods=["POST"])
def add():
    title = request.form["title"]