diff --git a/README.md b/README.md index c89f7a6..8c8ae81 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,4 @@ # flask-empty-project-shell + +## Now fleshed out with basic roots An empty project shell for structuring new Flask projects diff --git a/app/__init__.py b/app/__init__.py index e69de29..0740f77 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -0,0 +1,12 @@ +from flask import Flask +from config import config + +def create_app(config_name): + app = Flask(__name__) + app.config.from_object(config[config_name]) + config[config_name].init_app(app) + + from .main import main as main_blueprint + app.register_blueprint(main_blueprint) + + return app \ No newline at end of file diff --git a/app/main/__init__.py b/app/main/__init__.py index e69de29..9ca777c 100644 --- a/app/main/__init__.py +++ b/app/main/__init__.py @@ -0,0 +1,5 @@ +from flask import Blueprint + +main = Blueprint('main', __name__) + +from . import views, errors \ No newline at end of file diff --git a/app/main/errors.py b/app/main/errors.py new file mode 100644 index 0000000..0a88fd3 --- /dev/null +++ b/app/main/errors.py @@ -0,0 +1,10 @@ +from flask import render_template +from . import main + +@main.app_errorhandler(404) +def page_not_found(e): + return render_template('404.html'), 404 + +@main.app_errorhandler(500) +def internal_server_error(e): + return render_template('500.html'), 500 \ No newline at end of file diff --git a/app/main/views.py b/app/main/views.py new file mode 100644 index 0000000..628b546 --- /dev/null +++ b/app/main/views.py @@ -0,0 +1,7 @@ +from flask import render_template +from . import main + + +@main.route('/', methods=['GET']) +def index(): + return render_template('index.html') \ No newline at end of file diff --git a/app/templates/404.html b/app/templates/404.html new file mode 100644 index 0000000..57db2e9 --- /dev/null +++ b/app/templates/404.html @@ -0,0 +1 @@ +404 \ No newline at end of file diff --git a/app/templates/500.html b/app/templates/500.html new file mode 100644 index 0000000..eb1f494 --- /dev/null +++ b/app/templates/500.html @@ -0,0 +1 @@ +500 \ No newline at end of file diff --git a/app/templates/index.html b/app/templates/index.html index e69de29..b2d525b 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -0,0 +1 @@ +index \ No newline at end of file diff --git a/config.py b/config.py index e69de29..1883f18 100644 --- a/config.py +++ b/config.py @@ -0,0 +1,25 @@ +import os +basedir = os.path.abspath(os.path.dirname(__file__)) + +class Config: + SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string' + + @staticmethod + def init_app(app): + pass + +class DevelopmentConfig(Config): + DEBUG = True + +class TestingConfig(Config): + TESTING = True + +class ProductionConfig(Config): + pass + +config = { + 'development': DevelopmentConfig, + 'testing': TestingConfig, + 'production': ProductionConfig, + 'default': DevelopmentConfig +} \ No newline at end of file diff --git a/flasky.py b/flasky.py index e69de29..4fe0027 100644 --- a/flasky.py +++ b/flasky.py @@ -0,0 +1,5 @@ +import os +from app import create_app + + +app = create_app(os.getenv('FLASK_CONFIG') or 'default') \ No newline at end of file