Python Django:找不到字段?

Python Django:找不到字段?,python,django,django-models,django-forms,Python,Django,Django Models,Django Forms,我总是出错 ImproperlyConfigured at /messages/compose/ Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form ComposeForm needs updating. 我完全理解错误指出的是什么,但我不明白为什么它会首先出现 这是django希望我更新的表单: from django import

我总是出错

ImproperlyConfigured at /messages/compose/
Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form ComposeForm needs updating.
我完全理解错误指出的是什么,但我不明白为什么它会首先出现

这是django希望我更新的表单:

from django import forms
from .models import DirectMessage

class ComposeForm(forms.ModelForm):
    class Meta:
        model = DirectMessage
这是我的模型(包括字段):

也许我的语法有问题,或者我遗漏了一个明显的基本错误。如需任何帮助,请告知我您是否需要更多信息/背景。谢谢大家!

如中所述:

强烈建议您使用“字段”属性显式设置表单中应编辑的所有字段。如果表单意外地允许用户设置某些字段,特别是在向模型添加新字段时,如果不这样做,则很容易导致安全问题。根据表单的呈现方式,问题甚至可能在网页上不可见

另一种方法是自动包含所有字段,或者只将部分字段列入黑名单。众所周知,这种基本方法的安全性要低得多,并导致在主要网站(例如)上严重利用漏洞

因此,无论模型中定义了哪些字段,都应该在
中显式包含
字段
变量。这必须是ModelForm中需要的模型所有字段的元组。您也可以将该值指定为
“\uuuu all\uuuu”

这是:

在Django 1.6中更改:

在版本1.6之前,“all”快捷方式不存在,但省略fields属性具有相同的效果。现在不推荐同时省略字段和排除,但在版本1.8之前将继续工作

我完全理解错误指出的是什么,但我不知道 明白为什么它会首先出现吗

呃。。。因为您的模型表单没有明确指定
字段
列表或
排除
列表

这是django希望我更新的表单: 类DirectMessageAdmin(admin.ModelAdmin):


这不是ModelForm,这是ModelAdmin。鉴于你的错误信息中的url,我认为这与你的管理员没有任何关系…

ahhh,看起来在我紧张的状态下,我误读了错误。让我用我的表格更新这个问题
from django.db import models
from django.contrib.auth.models import User

# Create your models here.
user_obj = User.objects.get(username = 'jess')

class DirectMessage(models.Model):
    subject = models.CharField(max_length =150)
    body = models.CharField(max_length =3000)
    sender = models.ForeignKey(User, related_name='sent_direct_messages', null=True, blank=True)
    receiver = models.ForeignKey(User, related_name='recieved_direct_messages', null=True, blank=True)
    sent = models.DateTimeField(auto_now_add=False, auto_now=False, null=True, blank=True)
    read = models.DateTimeField(auto_now_add=False, auto_now=False, null=True, blank=True)

    def __unicode__(self):
        return self.subject