每当我尝试运行时,我都会收到以下错误。我已经研究过一个解决方案,但我无法使其发挥作用。
异常类型:ValueError 例外价值:
ModelForm没有指定模型类。 异常位置:/usr/local/lib/python2.7/dist-packages/django/forms/models.py在 init ,第275行 Python可执行文件:/ usr / bin / python Python版本:2.7.6
Erro Traceback
文件“/home/ubuntu/workspace/envelope/views.py”在cad_professor中 67. form = ProfessorForm()
init 中的文件“/usr/local/lib/python2.7/dist-packages/django/forms/models.py” 275.引发ValueError('ModelForm没有指定模型类。')
views.py
@login_required(login_url='/login/')
def cad_professor(request):
context = {}
if request.method == 'POST':
form = ProfessorForm(request.POST)
if form.is_valid():
form.save()
context['success'] = True
else:
form = ProfessorForm()
context['form'] = form
template_name = 'envelope/cad_professor.html'
return render(request,template_name , context)
forms.py
from django import forms
from .models import Professor
class ProfessorForm(forms.ModelForm):
class meta:
model = Professor
答案 0 :(得分:2)
您的meta
拼写错误。改为:
class ProfessorForm(forms.ModelForm):
class Meta:
model = Professor