Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brettlangdon/flask-defer
Flask extension to help register functions to run at the end of the current request.
https://github.com/brettlangdon/flask-defer
Last synced: 27 days ago
JSON representation
Flask extension to help register functions to run at the end of the current request.
- Host: GitHub
- URL: https://github.com/brettlangdon/flask-defer
- Owner: brettlangdon
- License: mit
- Created: 2016-11-28T20:45:57.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-11-29T12:54:25.000Z (about 8 years ago)
- Last Synced: 2024-11-15T18:49:29.579Z (about 2 months ago)
- Language: Python
- Size: 10.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
Flask-Defer
=========.. image:: https://badge.fury.io/py/flask-defer.svg
:target: https://badge.fury.io/py/flask-defer
.. image:: https://travis-ci.org/brettlangdon/flask-defer.svg?branch=master
:target: https://travis-ci.org/brettlangdon/flask-deferEasily register a function to execute at the end of the current request.
Installation
~~~~~~~~~~~~.. code:: bash
pip install Flask-Defer
Usage
~~~~~Passing a function and it's arguments to `flask_defer.after_request` will register that function to execute when the Flask request has ended.
If a call to `flask_defer.after_request` happens outside of a request context then the function will be executed immediately.
.. code:: python
from flask import Flask
from flask_defer import FlaskDefer, after_requestapp = Flask(__name__)
FlaskDefer(app)def defer_me(name, say_hello=False):
if say_hello:
print 'Saying hello to, {name}'.format(name=name)@app.route('/')
def index():
print 'Start of request method'# Defer `defer_me` until after the current request has finished
after_request(defer_me, 'name', say_hello=True)print 'Ending request method'
return 'Thanks!'
if __name__ == '__main__':
app.run().. code:: bash
$ python example.py
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
Start of request method
Ending request method
Saying hello to, name
127.0.0.1 - - [28/Nov/2016 15:41:39] "GET / HTTP/1.1" 200 -