Created
September 1, 2012 11:34
-
-
Save alexanderjulo/3570563 to your computer and use it in GitHub Desktop.
with request context decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class with_request_context(object): | |
def __init__(self, f, app=None, request=None): | |
self.f = f | |
if app: | |
self.app = app | |
else: | |
self.app = www | |
if request: | |
self.request = request | |
else: | |
self.request = '/' | |
self.__name__ = f.__name__ + 'with_request_context' | |
def __call__(self, *args): | |
with self.app.test_request_context(self.request): | |
return self.f(*args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this.And if you have a better way to handle this problem.Following is your email: http://librelist.com/browser/flask/2012/9/1/flask-sqlalchemy-and-apparently-celery-or-threading/ .