Django model “doesn't declare an explicit app_label”

后端 未结 28 1924
無奈伤痛
無奈伤痛 2020-11-27 15:38

I\'m at wit\'s end. After a dozen hours of troubleshooting, probably more, I thought I was finally in business, but then I got:

Model class django.contrib.co         


        
28条回答
  •  暖寄归人
    2020-11-27 15:53

    as a noob using Python3 ,I find it might be an import error instead of a Django error

    wrong:

    from someModule import someClass
    

    right:

    from .someModule import someClass
    

    this happens a few days ago but I really can't reproduce it...I think only people new to Django may encounter this.here's what I remember:

    try to register a model in admin.py:

    from django.contrib import admin
    from user import User
    admin.site.register(User)
    

    try to run server, error looks like this

    some lines...
    File "/path/to/admin.py" ,line 6
    tell you there is an import error
    some lines...
    Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label
    

    change user to .user ,problem solved

提交回复
热议问题