擅长:python、mysql、java
<p>它们有一个<code>__dict__</code>属性(这是一个标准属性):<code>my_model.__dict__['my_field']</code></p>
<p>然而,实现这种访问的标准方法是使用<code>getattr</code>:<code>getattr(my_model, 'my_field')</code>。在</p>
<p>请参见:<a href="http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes" rel="nofollow">http://docs.python.org/reference/datamodel.html#new-style-and-classic-classes</a>。还要查找<code>__slots__</code>以了解不具有此属性的类。在</p>
<p>正如Jeremy在上面指出的,任何使用django寻找此功能的人可能也会考虑使用<code>queryset.values()</code>(<a href="https://docs.djangoproject.com/en/dev/ref/models/querysets/#values" rel="nofollow">https://docs.djangoproject.com/en/dev/ref/models/querysets/#values</a>)。在</p>