48 lines
1.2 KiB
Python
48 lines
1.2 KiB
Python
import os
|
|
|
|
from flask import Flask, render_template
|
|
from werkzeug import SharedDataMiddleware
|
|
|
|
|
|
def create_app():
|
|
app = Flask(__name__, instance_relative_config=True)
|
|
|
|
app.config.from_mapping(
|
|
SQLALCHEMY_DATABASE_URI="sqlite:///{}".format(os.path.join(app.instance_path, 'files.sqlite')),
|
|
SQLALCHEMY_TRACK_MODIFICATIONS=False,
|
|
USERNAME='dev',
|
|
PASSWORD='secret',
|
|
SECRET_KEY='1337',
|
|
UPLOAD_FOLDER='uploads'
|
|
)
|
|
|
|
app.config.from_pyfile('config.py')
|
|
app.wsgi_app = SharedDataMiddleware(app.wsgi_app, {'/uploads': app.config['UPLOAD_FOLDER']})
|
|
|
|
try:
|
|
os.makedirs(app.instance_path)
|
|
except OSError:
|
|
pass
|
|
|
|
from files.models import db
|
|
db.init_app(app)
|
|
|
|
from files import commands
|
|
commands.init_app(app)
|
|
|
|
from files import auth
|
|
app.register_blueprint(auth.bp)
|
|
|
|
from files import categories
|
|
app.register_blueprint(categories.bp)
|
|
|
|
from files import about
|
|
app.register_blueprint(about.bp)
|
|
app.add_url_rule('/about', endpoint='about')
|
|
|
|
from files import files
|
|
app.register_blueprint(files.bp)
|
|
app.add_url_rule('/', endpoint='index')
|
|
|
|
return app
|