【发布时间】:2017-05-09 17:55:43
【问题描述】:
我正在使用django-1.10 并希望使用pinax-notifications-4.0 为我的应用程序实现一些通知行为。
我正在关注quickstart 将其包含到INSTALLED_APP
INSTALLED_APPS = [
# ...
"pinax.notifications",
# ...
]
然后和usage 指南。
首先是在heat/handler.py
中创建通知类型from pinax.notifications.models import NoticeType
from django.conf import settings
from django.utils.translation import ugettext_noop as _
def create_notice_types(sender, **kwargs):
NoticeType.create(
"heat_detection",
_("Heat Detected"),
_("you have detected a heat record")
)
在应用迁移后,再次调用处理程序创建通知。 heat.apps.py
from .handlers import create_notice_types
from django.apps import AppConfig
from django.db.models.signals import post_migrate
class HeatConfig(AppConfig):
name = 'heat'
def ready(self):
post_migrate.connect(create_notice_types, sender=self)
最后将 appconfig 包含到 heat.__init__.py
default_app_config = 'heat.apps.HeatConfig'
但是当尝试运行这些时:
python manage.py makemigrations pinax.notifications
我收到此错误:RuntimeError: Model class django.contrib.sites.models.Site doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
然后我尝试将INSTALLED_APPS 中的pinax.notifications 更改为pinax-notifications。服务器给我这个错误:ImportError: No module named pinax-notifications
如何做到这一点?
【问题讨论】:
-
您的
INSTALLED_APPS中有django.contrib.sites吗? -
我添加并将
pinax.notifications更改为pinax现在它的工作我不知道为什么但文档明确指出pinax.notifications -
也看到了。
-
但在此之前我在
heat.__init__.py中评论了default_app_config = 'heat.apps.HeatConfig',当尝试取消评论并尝试运行服务器时,我遇到了错误django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet. -
您可以只使用
INSTALLED_APPS中的整个虚线路径,而不是使用default_app_config
标签: python django notifications pinax