python - 错误: Maximum recursion depth on using flask-babel method with Nereid

标签 python flask tryton

我从 Nereid 3.2 得到最大递归深度错误。 我发现这个错误的主要原因是 Babel dateformat filter在 jinja 模板中,例如

{{ blog_date | dateformat(format='MMM YY') }}

调试时我发现可能是Nereid的speaklater因为延迟渲染功能导致了该问题。

最佳答案

终于我找到了解决方案,这就是我到达那里的方法。

flask 的递归深度错误问题是不容易找到问题的根本原因,因此通过命中和尝试方法我得到了问题的尾部。

方法调用流程是这样的:

日期格式过滤器 > format_date() > to_user_timezone() > get_timezone()

现在获取时区方法被覆盖 here如:

def get_timezone():
    """
    Returns the timezone that should be used for this request as
    `pytz.timezone` object.  This returns `None` if used outside of
    a request.
    """
    ctx = _request_ctx_stack.top
    tzinfo = getattr(ctx, 'babel_tzinfo', None)
    if tzinfo is None:
    babel = ctx.app.extensions['babel']
    if babel.timezone_selector_func is None:
        if not current_user.is_anonymous() and current_user.timezone:
        tzinfo = timezone(current_user.timezone)
        else:
        tzinfo = timezone(ctx.request.nereid_website.timezone)
    else:
        rv = babel.timezone_selector_func()
        if rv is None:
        tzinfo = babel.default_timezone
        else:
        if isinstance(rv, basestring):
            tzinfo = timezone(rv)
        else:
            tzinfo = rv
    ctx.babel_tzinfo = tzinfo
    return tzinfo

flask.ext.babel.get_timezone = get_timezone

来自here它正在调用 function field timezone在 nereid_website 中,默认返回公司的 timezone ,一个非必填字段。

最后,我在 PR#229 中解决了这个问题。欢迎审稿!

关于python - 错误: Maximum recursion depth on using flask-babel method with Nereid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26998102/

相关文章:

python - 将变量传递给 Flask WTForm

python - Flask-RESTful 类方法内的断点不会在 PTVS 上命中

python - 无法找出 “if/else”陈述

python - 如何简单地从标准输入读取由空格或空格分隔的输入

python - 如何在 SQLAlchemy 中嵌套连词 or and 和 _

postgresql - 使用docker-compose文件启动Tryton服务器

python cPickle unpickling错误无效加载 key

python - 你如何在 Appengine 上使用 xlrd 读取 excel 文件

python-2.7 - 如何运行我的远程服务器 Tryton 3.6.0?