Django 模型“不声明显式 app_label" [英] Django model "doesn't declare an explicit app_label"

查看:43
本文介绍了Django 模型“不声明显式 app_label"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经无计可施了.经过十几个小时的故障排除,可能更多,我以为我终于开始营业了,但后来我得到了:

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.contenttypes.models.ContentType doesn't declare an explicit app_label 

网络上关于此的信息太少了,而且没有任何解决方案可以解决我的问题.任何建议将不胜感激.

There is SO LITTLE info on this on the web, and no solution out there has resolved my issue. Any advice would be tremendously appreciated.

我使用的是 Python 3.4 和 Django 1.10.

I'm using Python 3.4 and Django 1.10.

来自我的 settings.py:

From my settings.py:

INSTALLED_APPS = [
    'DeleteNote.apps.DeletenoteConfig',
    'LibrarySync.apps.LibrarysyncConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

我的 apps.py 文件如下所示:

And my apps.py files look like this:

from django.apps import AppConfig


class DeletenoteConfig(AppConfig):
    name = 'DeleteNote'

from django.apps import AppConfig


class LibrarysyncConfig(AppConfig):
    name = 'LibrarySync'

推荐答案

您是否遗漏了将应用程序名称放入设置文件中?myAppNameConfig 是由 .manage.py createapp myAppName 命令在 apps.py 中生成的默认类.其中 myAppName 是您的应用程序的名称.

Are you missing putting in your application name into the settings file? The myAppNameConfig is the default class generated at apps.py by the .manage.py createapp myAppName command. Where myAppName is the name of your app.

settings.py

settings.py

INSTALLED_APPS = [
'myAppName.apps.myAppNameConfig',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]

通过这种方式,设置文件会找出您要调用的应用程序.您可以通过在

This way, the settings file finds out what you want to call your application. You can change how it looks later in the apps.py file by adding the following code in

myAppName/apps.py

myAppName/apps.py

class myAppNameConfig(AppConfig):
    name = 'myAppName'
    verbose_name = 'A Much Better Name'

这篇关于Django 模型“不声明显式 app_label"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆