how can i get current_user in flask-script.
zlhgo opened this issue · 1 comments
zlhgo commented
i have tried ctx = app.test_request_context('/?api_key=xxx') ctx.push(), but i get AnonymousUser in @manager.command function. is there another way to get current_user in @manager.command function. thanks.
zlhgo commented
i have found a way to solve this question.
from flask.ext.login import current_user
from app import app, manager
def create_ctx():
ctx = app.test_request_context(path=path, base_url=base_url)
ctx.push()
return ctx
@manager.command
def hello():
with create_ctx() as ctx:
print current.id
ctx.pop()
it works.maybe there are another better ways.
thank you.