RemovedInDjango19Warning:模型未声明显式 app_label
RemovedInDjango19Warning: Model doesn't declare an explicit app_label
已经历
但是答案无法解决我的问题,所以再问一次。
我有一个应用已添加到 INSTALLED_APPS 的设置中。
每当我 运行 manage.py runserver
,我都会收到此警告,
[trimmed path to project]/catalog/models.py:9: RemovedInDjango19Warning: Model class catalog.models.Category doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Category(models.Model):
来自我的应用程序的代码,
signals.py
from django.db.models.signals import post_save
from django.dispatch import receiver
from models import Category
@receiver(post_save, sender=Category)
def someSignal(sender, **kwargs):
pass
apps.py
from django.apps import AppConfig
class CatalogConfig(AppConfig):
name = 'catalog'
verbose_name = 'Catalogue'
init.py
import signals
default_app_config = 'catalog.apps.WhosConfig'
Django 版本 1.8.2 Python 2.7.8
您正在导入 models.py,然后再配置应用 运行。
要修复它,您可以在 CatalogConfig.ready
方法中导入和配置信号。
像这样:
signals.py
def someSignal(sender, **kwargs):
pass
apps.py
from django.apps import AppConfig
from django.db.models.signals import post_save
class CatalogConfig(AppConfig):
name = 'catalog'
verbose_name = 'Catalogue'
def ready(self):
from .signals import someSignal
post_save.connect(
receiver=someSignal,
sender=self.get_model('Category')
)
您可能需要检查准备方法 in documentation
我在 运行 测试时遇到了这个问题,这只是一个改变的问题:
from .models import MyModel
至
from apps.myapp.models import MyModel
已经历
但是答案无法解决我的问题,所以再问一次。
我有一个应用已添加到 INSTALLED_APPS 的设置中。
每当我 运行 manage.py runserver
,我都会收到此警告,
[trimmed path to project]/catalog/models.py:9: RemovedInDjango19Warning: Model class catalog.models.Category doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
class Category(models.Model):
来自我的应用程序的代码,
signals.py
from django.db.models.signals import post_save
from django.dispatch import receiver
from models import Category
@receiver(post_save, sender=Category)
def someSignal(sender, **kwargs):
pass
apps.py
from django.apps import AppConfig
class CatalogConfig(AppConfig):
name = 'catalog'
verbose_name = 'Catalogue'
init.py
import signals
default_app_config = 'catalog.apps.WhosConfig'
Django 版本 1.8.2 Python 2.7.8
您正在导入 models.py,然后再配置应用 运行。
要修复它,您可以在 CatalogConfig.ready
方法中导入和配置信号。
像这样:
signals.py
def someSignal(sender, **kwargs):
pass
apps.py
from django.apps import AppConfig
from django.db.models.signals import post_save
class CatalogConfig(AppConfig):
name = 'catalog'
verbose_name = 'Catalogue'
def ready(self):
from .signals import someSignal
post_save.connect(
receiver=someSignal,
sender=self.get_model('Category')
)
您可能需要检查准备方法 in documentation
我在 运行 测试时遇到了这个问题,这只是一个改变的问题:
from .models import MyModel
至
from apps.myapp.models import MyModel