python - 如何在flask登录中实现localize_callback

标签 python flask flask-login

我看到官方文档,它没有任何回调实现的细节。

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/

相关文章:

authentication - Flask-HttpAuth 和 Flask-Login

python - Flask:request.form ["xxxxx"]、request.form.get ("xxxxxx")和request.args.get ("xxxxx")之间的区别?

python - 限制 Azure 应用程序访问 OneDrive 中的特定文件夹

Python-sql,使用记录的示例,但收到 'No module named ' sql.aggregate' 错误

python - 使用 Virtualenv 和 Apache 部署 Django

python - 如何将 recaptcha 自定义主题与 Flask-WTF 一起使用

python - 存储发布数据以供使用 Flask-Login 进行身份验证后使用

python - 创建多处理数组时出现段错误

python - 如何在 Flask 的扩展名为 .jhtml 的模板中启用自动转义?

python - 使用gunicorn+Flask时Google Cloud Vision没有响应