Python Django模型表单和可见_字段

Python Django模型表单和可见_字段,python,django,Python,Django,我试图使用Django的ModelForm,但通过使用fields属性来限制显示的字段数量。下面是我代码的相关部分 django和python版本 models.py: forms.py 样板 我看到了一些问题 1) 当我访问页面时,模板也会显示创建的_at字段,尽管Meta.fields没有该列 2) 第一次在shell中导入form类时,我看到一个弃用警告,即使我在Meta类中有fields属性 >>> from account.forms import RegisterF

我试图使用Django的ModelForm,但通过使用fields属性来限制显示的字段数量。下面是我代码的相关部分

django和python版本 models.py: forms.py 样板 我看到了一些问题

1) 当我访问页面时,模板也会显示创建的_at字段,尽管Meta.fields没有该列

2) 第一次在shell中导入form类时,我看到一个弃用警告,即使我在Meta类中有fields属性

>>> from account.forms import RegisterForm
/home/django/django_project/account/forms.py:4: RemovedInDjango18Warning: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is deprecated - form RegisterForm needs updating
  class RegisterForm(forms.ModelForm):

任何指针?

将ModelForm的内部
元类的
排除
属性设置为要从表单中排除的字段列表

你的情况是这样的

class RegisterForm(forms.ModelForm):

    class Meta:
        model=User
        exclude = ['created_at']

请注意,在Django 1.7+中,现在需要通过
exclude

指定要排除的字段,您使用的是哪个Django版本?python 2.7,Django 1.7
class RegisterForm(forms.ModelForm):

    class Meta:
        model=User
        fields = ['name', 'email', 'password']
  {% for field in form.visible_fields %}
        {{ field.errors }}
        {{ field.label_tag}} {{ field}}
  {% endfor %}
>>> from account.forms import RegisterForm
/home/django/django_project/account/forms.py:4: RemovedInDjango18Warning: Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is deprecated - form RegisterForm needs updating
  class RegisterForm(forms.ModelForm):
class RegisterForm(forms.ModelForm):

    class Meta:
        model=User
        exclude = ['created_at']