ModelForm 在使用模型表单时没有指定模型 class

ModelForm has no model class specified when use model forms

我创建了一个网页,用于将数据输入数据库的数据输入操作员。我使用 modelForm 来获取数据。当我使用它时,django 会引发 "ModelForm has no model class specified" 的错误。我该怎么办?

model.py

class Person(models.Model):

    NIC = models.CharField(unique=True,max_length=12)
    FName = models.CharField(max_length=30)
    LName = models.CharField(max_length=30)
    FullName = models.CharField(max_length=100)
    DOB = models.DateField()
    Nationality = models.CharField(max_length=20)
    AddressLine1 = models.CharField(max_length=100)
    AddressLine2 = models.CharField(max_length=100)
    AddressLine3 = models.CharField(max_length=100)
    AddressLine4 = models.CharField(max_length=100, null=True,blank=True)
    ContactNum = models.CharField(max_length=12)
    Email = models.EmailField()
    FacebookProf = models.CharField(max_length=100,null=True,blank=True)
    LinkedInProf = models.CharField(max_length=100,null=True,blank=True)
    PImage = models.ImageField(upload_to= Person_directory_path,null=True)
    Objective = models.TextField()
    CVPDF = models.ImageField(upload_to=Person_directory_path)
    SpecialNotes = models.TextField(blank=True,null=True)
    Department = models.ManyToManyField("Department")
    Post = models.ManyToManyField("Post")
    Degree = models.ManyToManyField("Degree",through="Person_Degree",null=True)
    Interview = models.ManyToManyField("Interview",through='Person_Interview',null=True)

    def __str__(self):
        return self.NIC, self.FName, self.LName, self.FullName, self.Email

forms.py

from django.forms import ModelForm

from django import forms

from .models import Person

class Interview_Form(forms.ModelForm):

    class meta:
        model = Person
        fields = ['NIC', 'FName', 'LName','FullName','Email']

views.py

from .forms import *

def deo(request):

    deoForm = Interview_Form()
    context = {
        'deoForm':deoForm,
    }
    return render(request, 'deo.html', context)

对我来说,您似乎是从 django.forms 导入 ModelForm,但是当您创建 Interview_form 时,您使用的是 forms.ModelForm。

你应该只使用 ModelForm。