Django ModelForm has no model class specified

后端 未结 9 440
误落风尘
误落风尘 2021-02-02 08:36

I am trying to use ModelForm:

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

class Car(models.Model):
    carnumber = models.CharField(max_leng         


        
相关标签:
9条回答
  • 2021-02-02 09:16

    In my case the error was due to me wirting :

    models = User
    


    instead of :

    model = User
    
    0 讨论(0)
  • 2021-02-02 09:17

    If this is a copy and past, you have a typo. I would highly recommend you use an IDE or something with error checking. Eclipse is what I use. It will save you a ton of time from little annoyances like this.

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

    Your typo is right on the end of Car. The little apostrophe thing.

    0 讨论(0)
  • 2021-02-02 09:20

    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
    
    0 讨论(0)
  • 2021-02-02 09:22

    see your code in your defined form code area.there may be error either with =,: and meta,Meta .so please look carefully if case sensitive error or any signs over there

    0 讨论(0)
  • 2021-02-02 09:24

    Just do this method your page will run:

    class PickForm(ModelForm):
      class Meta:
        model = Car
        fields = "__all__"
    
    0 讨论(0)
  • 2021-02-02 09:26

    my error was because I wrote meta instead of Meta

    0 讨论(0)
提交回复
热议问题