我正在使用 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:模型类 django.contrib.sites.models.Site 未声明显式 app_label 并且不在 INSTALLED_APPS 中的应用程序中。
然后我尝试将 INSTALLED_APPS
中的 pinax.notifications
更改为 pinax-notifications
。服务器给我产生了这个错误:ImportError:没有名为 pinax-notifications 的模块
如何做到这一点?
最佳答案
我能够通过更改 heat.apps.py 文件来解决这个问题
from django.apps import AppConfig
from django.db.models.signals import post_migrate
from .handlers import create_notice_types
class HeatConfig(AppConfig):
name = 'heat'
def ready(self):
post_migrate.connect(create_notice_types, sender=self)
对此。
from django.apps import AppConfig
class HeatConfig(AppConfig):
name = 'heat'
def ready(self):
from django.db.models.signals import post_migrate
from .handlers import create_notice_types
post_migrate.connect(create_notice_types, sender=self)
关于python - 在 django 应用程序中集成 pinax 通知失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41311399/