django.utils.functional .__ proxy__对象是什么,它有什么帮助? [英] What is a django.utils.functional.__proxy__ object and what it helps with?

查看:100
本文介绍了django.utils.functional .__ proxy__对象是什么,它有什么帮助?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无意中遇到了 django.utils.functional .__ proxy __ 对象很多次,最后一次是在以下代码段中:

I stumbled across a django.utils.functional.__proxy__ object many times, last time in the following bit of code:

def formfield_for_choice_field(self, db_field, request, **kwargs):
    print db_field.help_text

(打印结果为< django.utils.functional .__ proxy__对象位于0x7fc6940106d0>

现在,为什么东西包裹在这个物体上?它的主要目的是什么?更重要的是,如何访问代理对象背后的值?我查看了Django的源代码,看到了一些关于延迟评估的信息,但是包装和包装的对象太多,无法完全理解正在发生的事情。

Now, why are things wrapped around this object? What is the main purpose of it? And more important, how can I access the value behind the proxy object? I viewed Django's source, I've seen something about lazy evaluation, but there are too many wrappers and wrapped objects to fully comprehend what's going on. Any details on this would be highly appreciated.

推荐答案

这是一个翻译字符串,该字符串已被标记为已翻译,但其字符串在字符串中使用对象之前,无法确定实际的翻译结果。请参阅Django文档: https://docs.djangoproject.com/en/ dev / ref / unicode /#translated-strings

It is a translation string – a string that has been marked as translated but whose actual translation result isn’t determined until the object is used in a string. See Django documentation: https://docs.djangoproject.com/en/dev/ref/unicode/#translated-strings.

调用 unicode(object)将生成Unicode字符串。另外,如果调用对象的 __ dict __ ,则可以在 _proxy ____ args 下找到其数据。

Calling unicode(object) will generate a Unicode string. Also, if you call __dict__ of the object, you can find its data under _proxy____args.

这篇关于django.utils.functional .__ proxy__对象是什么,它有什么帮助?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆