Skip to content

Commit

Permalink
Added example of how to setup Flask-Moment using a Flask app factory
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwidman committed Nov 19, 2015
1 parent 23f13af commit 5a27fff
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ Step 2: In your `<head>` section of your base template add the following code:
{{ moment.include_moment() }}
</head>

This extension also supports the [Flask application factory pattern](http://flask.pocoo.org/docs/latest/patterns/appfactories/) by allowing you to create a Moment object and then separately initialize it for an app:

moment = Moment()

def create_app(config):
app = Flask(__name__)
app.config.from_object(config)
# initialize moment on the app within create_app()
moment.init_app(app)

app = create_app(prod_config)

Note that jQuery is required. If you are already including it on your own then you can remove the `include_jquery()` line. Secure HTTP is used if the request under which these are executed is secure.

The `include_jquery()` and `include_moment()` methods take two optional arguments. If you pass `version`, then the requested version will be loaded from the CDN. If you pass `local_js`, then the given local path will be used to load the library.
Expand Down

0 comments on commit 5a27fff

Please sign in to comment.