Files
doc.2020.app/flaskpages/__init__.py
2021-11-19 21:07:45 +00:00

39 lines
1.1 KiB
Python

import os
from flask import Flask
from flaskpages import pages
import logging
def create_app(test_config=None):
"""Create and configure an instance of the Flask application."""
app = Flask(__name__, instance_relative_config=True)
app.config.from_mapping(
# a default secret that should be overridden by instance config
SECRET_KEY="dev",
URL_PREFIX = "/"
)
if not test_config:
# load the instance config, if it exists, when not testing
app.config.from_pyfile("cfg.py")
else:
# load the test config if passed in
app.config.update(test_config)
# ensure the instance folder exists
try:
os.makedirs(app.instance_path)
except OSError:
pass
if app.config["DEBUG"]:
app.logger.setLevel(logging.DEBUG)
@app.route("/hello")
def hello():
return "Hello, World!"
app.logger.debug(app.config)
app.register_blueprint(pages.create_bp(app), url_prefix = app.config["URL_PREFIX"], static_folder='static')
app.add_url_rule("/", endpoint="index")
return app