42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
import os
|
|
import sys
|
|
|
|
from flask import Flask, render_template, g, redirect, url_for
|
|
from datetime import datetime
|
|
|
|
def create_app(test_config=None):
|
|
# create and configure the app
|
|
app = Flask(__name__, instance_relative_config=True)
|
|
print(app.instance_path)
|
|
if test_config is None:
|
|
app.config.from_pyfile('config.py', silent=False)
|
|
else:
|
|
app.config.from_mapping(test_config)
|
|
# app.config['UPLOADDIR'] = os.path.join(app.instance_path, )
|
|
if not os.path.exists(app.config['UPLOADDIR']):
|
|
os.mkdir(app.config['UPLOADDIR'])
|
|
# print(app.config.keys())
|
|
try:
|
|
os.makedirs(app.instance_path)
|
|
except OSError:
|
|
pass
|
|
|
|
from . import db
|
|
db.init_app(app)
|
|
from . import auth
|
|
app.register_blueprint(auth.bp)
|
|
from . import admin
|
|
app.register_blueprint(admin.bp)
|
|
app.add_url_rule("/admin", endpoint="admin.index")
|
|
from . import user
|
|
app.register_blueprint(user.bp)
|
|
|
|
@app.route('/')
|
|
def index():
|
|
if g.user is not None and 'user_id' in g.user.keys():
|
|
if g.user['user_id'] == 0:
|
|
return redirect(url_for("admin.index"))
|
|
else:
|
|
return redirect(url_for("user.home"))
|
|
return render_template("auth/loginbase.html", cur_time=datetime.now())
|
|
return app |