本文介绍了Django ModelForm没有指定模型类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ModelForm:

I am trying to use ModelForm:

from django.db import models
from django.forms import ModelForm

class Car(models.Model):
    carnumber = models.CharField(max_length=5)

    def __unicode__(self):
        return self.carnumber

class PickForm(ModelForm):
    class Meta:
        Model = Car`

我已经检查了这一点,但找不到错误。当我在浏览器中调用视图时,它给我以下错误:

I have checked this and I cannot find my error. When I call the view in a browser, it gives me the following error:

ModelForm has no model class specified

我已经测试了使用相同URL的简单 foo bar代码调用模型的视图,但是当我尝试这段代码,我得到上面的类错误。

I have tested the view that calls the model with simple "foo bar" code at the same URL, but when I try this code, I get the class error above.

推荐答案

应该是 model 而不是 Model (并且没有尾随的`,但是我想那是一个错字):

It should be model instead of Model (and without the trailing `, but I guess that's a typo):

class PickForm(ModelForm):
    class Meta:
        model = Car

这篇关于Django ModelForm没有指定模型类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 12:43