Skip to content

Instantly share code, notes, and snippets.

@alexanderjulo
Created September 1, 2012 11:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexanderjulo/3570563 to your computer and use it in GitHub Desktop.
Save alexanderjulo/3570563 to your computer and use it in GitHub Desktop.
with request context decorator
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)
@yaoelvon
Copy link

yaoelvon commented Nov 1, 2016

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/ .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment