Exemplo n.º 1
0
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = secret.secret_key

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/bbs?charset=utf8mb4'.format(
            secret.database_password)
    db.init_app(app)
    mail.init_app(app)

    # 注册蓝图
    # 有一个 url_prefix 可以用来给蓝图中的每个路由加一个前缀
    app.register_blueprint(index_routes)
    app.register_blueprint(topic_routes, url_prefix='/topic')
    app.register_blueprint(reply_routes, url_prefix='/reply')
    app.register_blueprint(user_routes, url_prefix='/user')
    app.register_blueprint(message_routes, url_prefix='/message')

    app.template_filter()(count)
    app.template_filter()(formatted_time)

    # admin = Admin(app, name='web21', template_mode='bootstrap3')
    # admin.add_view(ModelView(User, db.session))
    # admin.add_view(ModelView(Topic, db.session))
    # admin.add_view(ModelView(Reply, db.session))
    # admin.add_view(ModelView(Messages, db.session))
    # Add administrative views here

    return app
Exemplo n.º 2
0
def configured_app():
    # web framework
    # web application
    # __main__
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = secret.secret_key
    # 现在 mysql root 默认用 socket 来验证而不是密码
    # uri = 'mysql+pymysql://[email protected]/bbs?charset=utf8mb4&unix_socket=/var/run/mysqld/mysqld.sock'
    uri = 'mysql+pymysql://root:{}@localhost/bbs?charset=utf8mb4'.format(
        secret.database_password)
    # uri = 'mysql+pymysql://root:[email protected]/bbs'
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)

    app.config['MAIL_SERVER'] = 'smtp.gmail.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = '******'
    app.config['MAIL_PASSWORD'] = secret.mail_password

    mail.init_app(app)

    register_routes(app)
    return app
Exemplo n.º 3
0
def configured_app():
    # web framework
    # web application
    # __main__
    app = Flask(__name__)
    app.secret_key = secret.secret_key

    uri = 'mysql+pymysql://[email protected]/websx?charset=utf8mb4&unix_socket=/var/run/mysqld/mysqld.sock'
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)

    app.config['MAIL_SERVER'] = 'smtp.exmail.qq.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = config.admin_mail
    app.config['MAIL_PASSWORD'] = secret.mail_password

    mail.init_app(app)

    register_routes(app)
    app.template_filter()(count)
    app.template_filter()(format_time)
    app.template_filter()(image1)
    app.template_filter()(name1)
    return app
Exemplo n.º 4
0
def configured_app():
    # web framework
    # web application
    # __main__
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = secret.secret_key

    # 现在 mysql root 默认用 socket 来验证而不是密码
    uri = 'mysql+pymysql://root:{}@127.0.0.1/web21?charset=utf8mb4'.format(secret.database_password)
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)

    app.config['MAIL_SERVER'] = 'smtp.exmail.qq.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = config.admin_mail
    app.config['MAIL_PASSWORD'] = secret.mail_password

    mail.init_app(app)
    redis_store.init_app(app)
    moment = Moment(app)
    bootstrap = Bootstrap(app)

    register_template_func(app)
    register_routes(app)
    return app
Exemplo n.º 5
0
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    app.secret_key = secret.secret_key

    uri = 'mysql+pymysql://root:{}@localhost/belife?charset=utf8mb4'.format(
        secret.database_password
    )
    # 用于连接数据库
    app.config['SQLALCHEMY_DATABASE_URI'] = uri
    # 如果设置成True(默认),Flask-SQLAlchemy 将会追踪对象的修改并且发送信号
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    # 初始化数据库
    db.init_app(app)

    # 自定义过滤器
    app.template_filter()(format_time)

    # flask-mail扩展发送电子邮件
    app.config['MAIL_SERVER'] = 'smtp.exmail.qq.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = config.admin_mail
    app.config['MAIL_PASSWORD'] = secret.mail_password
    mail.init_app(app)

    register_routes(app)
    return app
Exemplo n.º 6
0
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串是啥都行
    app.secret_key = config.secret_key

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/myweb?charset=utf8mb4'.format(
            secret.database_password)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    mail.init_app(app)

    app.register_blueprint(index_routes)
    app.register_blueprint(topic_routes, url_prefix='/topic')
    app.register_blueprint(reply_routes, url_prefix='/reply')
    app.register_blueprint(todo_routes, url_prefix='/todo')
    app.register_blueprint(board_routes, url_prefix='/board')
    app.register_blueprint(todo_api)
    app.register_blueprint(mail_routes, url_prefix='/mail')

    app.template_filter()(count)

    admin = Admin(app, name='myweb', template_mode='bootstrap3')
    admin.add_view(ModelView(User, db.session))
    admin.add_view(ModelView(Topic, db.session))
    admin.add_view(ModelView(Reply, db.session))
    admin.add_view(ModelView(Todo, db.session))
    admin.add_view(ModelView(Token, db.session))
    admin.add_view(ModelView(Messages, db.session))
    admin.add_view(ModelView(Board, db.session))
    # Add administrative views here

    return app
Exemplo n.º 7
0
def configured_app():
    """配置app"""
    app = Flask(__name__)
    app.jinja_env.auto_reload = True
    app.secret_key = setting.secret_key
    app.config['TEMPLATES_AUTO_RELOAD'] = True
    app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    app.config['SQLALCHEMY_DATABASE_URI'] = \
        'mysql+mysqlconnector://root:{}@localhost/PythonForum?charset=utf8mb4'.format(secret.database_password)
    db.init_app(app)

    app.config['MAIL_SERVER'] = 'smtp.163.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = setting.admin_mail
    app.config['MAIL_PASSWORD'] = secret.mail_password
    mail.init_app(app)
    """载入蓝图"""
    app.register_blueprint(index_routes)
    app.register_blueprint(topic_routes, url_prefix='/topic')
    app.register_blueprint(reply_routes, url_prefix='/reply')
    app.register_blueprint(mail_routes, url_prefix='/mail')
    app.register_blueprint(error_routes)
    """载入过滤器"""
    app.template_filter()(format_time)
    app.template_filter()(last_active_time)
    """载入后台管理系统"""
    admin = Admin(app, name='PythonForum', template_mode='bootstrap3')
    admin.add_view(ModelView(User, db.session))
    admin.add_view(ModelView(Topic, db.session))
    admin.add_view(ModelView(Reply, db.session))
    return app
Exemplo n.º 8
0
Arquivo: app.py Projeto: minnzhang/BBS
def configured_app():
    app = Flask(__name__)
    app.secret_key = secret.secret_key
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/BBS?charset=utf8mb4'.format(
        secret.database_password
    )
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    mail.init_app(app)
    socketio.init_app(app)

    register_routes(app)
    return app
Exemplo n.º 9
0
def configured_app():
    app = Flask(__name__)

    app.secret_key = secret.secret_key
    register_routes(app)

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/{}?charset=utf8mb4'.format(
            secret.mysql_password, secret.project_name)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    db.init_app(app)
    mail.init_app(app)

    return app
Exemplo n.º 10
0
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    app.secret_key = secret.secret_key

    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/{}?charset=utf8mb4'.format(
            secret.database_password, secret.database_name)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    mail.init_app(app)
    admin.init_app(app)

    register_routes(app)
    return app
Exemplo n.º 11
0
def configured_app():
    # web framework
    # web application
    # __main__
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = secret.secret_key

    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/flask_bbs?charset=utf8mb4'.format(
        secret.database_password
    )
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    mail.init_app(app)

    register_routes(app)
    return app
Exemplo n.º 12
0
Arquivo: app.py Projeto: spacexzm/BBS
def configured_app():
    app = Flask(__name__)
    # 设置 secret_key 来使用 flask 自带的 session
    # 这个字符串随便你设置什么内容都可以
    app.secret_key = config.secret_key

    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:{}@localhost/web19?charset=utf8mb4'.format(
        secret.database_password
    )
    db.init_app(app)
    migrate = Migrate(app, db)

    app.config['PERMANENT_SESSION_LIFETIME'] = timedelta(days=1)

    app.template_filter()(count)
    app.template_filter()(format_time)
    app.errorhandler(404)(not_found)

    # app.config['FLASK_ADMIN_SWATCH'] = 'cerulean'
    # admin = Admin(app, name='web19', template_mode='bootstrap3')
    # user_mv = UserModelView(User, db.session)
    # topic_mv = TopicModelView(Topic, db.session)
    #
    # admin.add_view(user_mv)
    # admin.add_view(topic_mv)
    # admin.add_view(ModelView(Board, db.session))
    # admin.add_view(ModelView(Reply, db.session))
    # admin.add_view(ModelView(Topic, db.session))
    # admin.add_view(ModelView(Reply, db.session))
    # Add administrative views here
    app.config['MAIL_SERVER'] = 'smtp.exmail.qq.com'
    app.config['MAIL_PORT'] = 465
    app.config['MAIL_USE_SSL'] = True
    app.config['MAIL_USERNAME'] = config.admin_mail
    app.config['MAIL_PASSWORD'] = secret.mail_password

    mail.init_app(app)

    register_routes(app)
    return app
Exemplo n.º 13
0

app = Flask(__name__)

app.secret_key = 'infs3202'

# set sqlite
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////' + os.path.join(
    app.root_path, 'db', 'data.sqlite')
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

app.config['SECRET_KEY'] = 'secret!'

# init app
db.init_app(app)
mail.init_app(app)
admin.init_app(app)
socketio.init_app(app)

register_routes(app)

# 自动 reload jinja
app.jinja_env.auto_reload = True
app.jinja_env.globals.update(current_user=current_user)

app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0

if __name__ == '__main__':
    context = ('cert.crt', 'key.key')
    config = dict(