-
Notifications
You must be signed in to change notification settings - Fork 8
Commit v0.4
kwmccabe edited this page Apr 17, 2018
·
15 revisions
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
apk 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 theapp
directory as a package. - Move
app = Flask(__name__)
fromflaskapp.py
into a function defined on this main app package. - Update values in
app.config
by passing an instance our newAppConfig
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 viaapp.config.from_object(AppConfig)
- Set a single value,
SECRET_KEY
. - The empty method
init_app()
will provide a location for other setup operations.
+import os
+
+class AppConfig(object):
+ SECRET_KEY = os.environ.get('SECRET_KEY') or 'my-super-secret-app-key'
+
+ @staticmethod
+ def init_app(app):
+ pass
- Replace
app = Flask(__name__)
withapp = create_app()
, as defined inapp/__init__.py
. - Create new route
/info/config
to displayapp.config
values.
-from flask import Flask
-app = Flask(__name__)
+from app import create_app
+app = create_app()
...
+@app.route('/info/config')
+def app_config():
+ cnf = dict(app.config)
+ return "Current Config : %s" % cnf
Commit-v0.3 | Commit-v0.4 | Commit-v0.5
- 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