【问题标题】:Django @method_decorator change from Python 2 to 3?Django @method_decorator 从 Python 2 更改为 3?
【发布时间】:2020-04-02 09:18:40
【问题描述】:

我目前正在将我的代码从 Python 2 迁移到 Python 3。我使用 Django,看起来我错过了一些东西。

我正在使用来自 Django 的装饰器 @method_decorator(func)。我的功能是这样定义的:

@decorator
func(action_meth, *args, **kwargs):
    result = action_meth(*args, **kwargs)
    # do 
    # something
    # with 
    # result

我的问题是 Python 2 和 Python 3 中的 args 值不一样,然后 args 不能用作我的 action_meth 的参数(我得到错误:action_meth 需要 2 个位置参数,但给出了 3 个)

首先,这段代码在 Python 2 中运行良好。但我在互联网上找不到任何关于 Python 3 迁移的信息。 我也很确定它来自 Django 的 method_decorator ......所以有人知道这个功能是否有任何变化吗?

这是我能得到的样本,

在 Python 2 中: 打印(args) => ([u'ID'],)

在 Python 3 中: 打印(args) => SELECT fieldA,fieldB, ...., fieldZ ....; args=(ID,)

感谢您的宝贵时间!

【问题讨论】:

    标签: django python-3.x python-2.7 migration


    【解决方案1】:

    什么都没有改变,这是代码中更深层次的另一个问题。

    也为这个问题的糟糕表述感到抱歉!

    【讨论】:

      猜你喜欢
      • 2018-08-31
      • 2016-03-16
      • 1970-01-01
      • 2023-03-26
      • 2019-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多