如何检索`__all__`的值

时间:2018-05-04 01:04:22

标签: python django

django/django/db/models/fields/__init__.py中有变量:

__all__ = [
    'AutoField', 'BLANK_CHOICE_DASH', 'BigAutoField', 'BigIntegerField',
    'BinaryField', 'BooleanField', 'CharField', 'CommaSeparatedIntegerField',
    'DateField', 'DateTimeField', 'DecimalField', 'DurationField',
    'EmailField', 'Empty', 'Field', 'FieldDoesNotExist', 'FilePathField',
    'FloatField', 'GenericIPAddressField', 'IPAddressField', 'IntegerField',
    'NOT_PROVIDED', 'NullBooleanField', 'PositiveIntegerField',
    'PositiveSmallIntegerField', 'SlugField', 'SmallIntegerField', 'TextField',
    'TimeField', 'URLField', 'UUIDField',
]

Django如何检索变量__all__?是吗 fields.__init__.__all__fields.__all__

1 个答案:

答案 0 :(得分:2)

Django不直接使用该变量,但它由Python import语句使用。如果要访问该值,可以执行以下操作:

from django.db.models import fields
print(fields.__all__)

请参阅this question以获取解释。