45 lines
1.3 KiB
Python
45 lines
1.3 KiB
Python
import os
|
|
|
|
from flask import Flask
|
|
from flaskpages import pages
|
|
import logging
|
|
from flask_flatpages import pygments_style_defs
|
|
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.route('/pygments.css')
|
|
def pygments_css():
|
|
return pygments_style_defs('tango'), 200, {'Content-Type': 'text/css'}
|
|
|
|
app.add_url_rule("/", endpoint="index")
|
|
|
|
return app |