-
Notifications
You must be signed in to change notification settings - Fork 8
Commit v0.4
app.create_app(), AppConfig, RUN apk add tzdata
- +4 -0 [M] web/Dockerfile
- +10 -0 [A] web/app/init.py
- +10 -0 [A] web/config.py
- +9 -2 [M] web/flaskapp.py
Run app add tzdata to install timezone support within the container Set the environment variable TZ America/Los_Angeles. The change should be visible at the existing route /info/date.
+# add tzdata to base image; set timezone environment variable
+RUN apk add --no-cache tzdata
+ENV TZ America/Los_Angeles
The init.py file (blank or otherwise) marks the app directory as a package. Move app = Flask(name) from flaskapp.py into a function defined on this main app package. Update values in app.config by passing an instance our new AppConfig object to the application. Call AppConfig.init_app() to perform other setup operations. Return an instance of the application.
+from flask import Flask
+from config import AppConfig
+
+def create_app():
+ app = Flask(__name__)
+
+ app.config.from_object(AppConfig)
+ AppConfig.init_app(app)
+
+ return app
A minimal AppConfig object, passed to the application via app.config.from_object(AppConfig) Set a single value, SECRET_KEY The empty method init_app() provides a place for other setup operations.
+# see http://flask.pocoo.org/docs/0.12/api/
+
+import os
+
+class AppConfig(object):
+ SECRET_KEY = os.environ.get('SECRET_KEY') or 'kp-cUHRAYH1n-sPaJICcEE2kOpU62mCk'
+
+ @staticmethod
+ def init_app(app):
+ pass
Replace app = Flask(name) with app = create_app(), as defined in app/init.py. Create new route /info/config to display app.config values.
-from flask import Flask
-app = Flask(__name__)
+
+# call create_app() in app/__init__.py
+from app import create_app
+app = create_app()
@app.route('/')
return "Current Datetime : %s" % ts
[email protected]('/info/config')
+def app_config():
+ cnf = dict(app.config)
+ return "Current Config : %s" % cnf
- FlaskApp Tutorial
- Table of Contents
- About
- Application Setup
- Modules, Templates, and Layouts
- Database Items, Forms, and CRUD
- List Filter, Sort, and Paginate
- Users and Login
- Database Relationships
- API Module, HTTPAuth and JSON
- Refactoring User Roles and Item Status
- AJAX and Public Pages