我看到官方文档,它没有任何回调实现的细节。
http://flask-login.readthedocs.io/en/latest/
By default, the LoginManager uses flash to display messages when a user is required to log in. These messages are in English. If you require localization, set the localize_callback attribute of LoginManager to a function to be called with these messages before they’re sent to flash, e.g. gettext. This function will be called with the message and its return value will be sent to flash instead.
我尝试使用
@login_manager.localize_callback
def localize_callback():
return 'local string'
当我这样做的时候。它告诉我
TypeError: 'NoneType' object is not callable
这里有什么问题吗?
最佳答案
我稍微调整了一下代码,虽然不优雅但它可以工作
def localize_callback(*args, **kwargs):
return 'local string'
login_manager.localize_callback = localize_callback
关于python - 如何在flask登录中实现localize_callback,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37605686/