RuntimeError: Model class django_messages.models.Message doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS
RuntimeError: Model class django_messages.models.Message doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS
我正在尝试使用 https://github.com/arneb/django-messages 包来发送消息,并尝试了以下
pip install git+https://github.com/arneb/django-messages.git
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'rest_framework',
'rest_framework.authtoken',
'oauth2_provider',
'api',
'localflavor',
'django_localflavor_us',
'django_countries',
'haystack',
'django_messages',
]
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^messages/', include('django_messages.urls')),
]
当我 运行 python manage.py runserver
我得到以下错误:
Unhandled exception in thread started by <function wrapper at 0x107cedaa0>
Traceback (most recent call last):
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/management/base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/management/base.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/urls/resolvers.py", line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/urls/resolvers.py", line 306, in urlconf_module
return import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/shivakrishna/shiva/Office_projects/iPitch/project /project /urls.py", line 23, in <module>
url(r'^messages/', include('django_messages.urls')),
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/conf/urls/__init__.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django_messages/urls.py", line 4, in <module>
from django_messages.views import *
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django_messages/views.py", line 11, in <module>
from django_messages.models import Message
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django_messages/models.py", line 48, in <module>
class Message(models.Model):
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/db/models/base.py", line 113, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class django_messages.models.Message doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
我能知道发生该错误的原因以及解决方法吗?
正如这个问题的答案所述:
您遇到的错误与在模型被应用程序初始化之前使用模型有关。
您在评论中声明您没有使用在初始化时执行的信号,因此搜索:
- 在初始化和使用您的模型或
django-messages
模型时调用的任何方法。如果有,请尝试将这些方法调用放在 app.py
. 中的 MyAppConfig
class 中
如果您的执行中有任何相对路径,请将其更改为确切的模块路径:
from .models import MyModel
from .messages import *
to
from apps.myapp.models import MyModel
django.messages import *
我正在尝试使用 https://github.com/arneb/django-messages 包来发送消息,并尝试了以下
pip install git+https://github.com/arneb/django-messages.git
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'rest_framework',
'rest_framework.authtoken',
'oauth2_provider',
'api',
'localflavor',
'django_localflavor_us',
'django_countries',
'haystack',
'django_messages',
]
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^messages/', include('django_messages.urls')),
]
当我 运行 python manage.py runserver
我得到以下错误:
Unhandled exception in thread started by <function wrapper at 0x107cedaa0>
Traceback (most recent call last):
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 121, in inner_run
self.check(display_num_errors=True)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/management/base.py", line 374, in check
include_deployment_checks=include_deployment_checks,
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/management/base.py", line 361, in _run_checks
return checks.run_checks(**kwargs)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/checks/registry.py", line 81, in run_checks
new_errors = check(app_configs=app_configs)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/checks/urls.py", line 14, in check_url_config
return check_resolver(resolver)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/core/checks/urls.py", line 24, in check_resolver
for pattern in resolver.url_patterns:
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/urls/resolvers.py", line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/utils/functional.py", line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/urls/resolvers.py", line 306, in urlconf_module
return import_module(self.urlconf_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/shivakrishna/shiva/Office_projects/iPitch/project /project /urls.py", line 23, in <module>
url(r'^messages/', include('django_messages.urls')),
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/conf/urls/__init__.py", line 50, in include
urlconf_module = import_module(urlconf_module)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django_messages/urls.py", line 4, in <module>
from django_messages.views import *
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django_messages/views.py", line 11, in <module>
from django_messages.models import Message
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django_messages/models.py", line 48, in <module>
class Message(models.Model):
File "/Users/shivakrishna/.virtualenvs/project /lib/python2.7/site-packages/django/db/models/base.py", line 113, in __new__
"INSTALLED_APPS." % (module, name)
RuntimeError: Model class django_messages.models.Message doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.
我能知道发生该错误的原因以及解决方法吗?
正如这个问题的答案所述:
您遇到的错误与在模型被应用程序初始化之前使用模型有关。
您在评论中声明您没有使用在初始化时执行的信号,因此搜索:
- 在初始化和使用您的模型或
django-messages
模型时调用的任何方法。如果有,请尝试将这些方法调用放在app.py
. 中的 如果您的执行中有任何相对路径,请将其更改为确切的模块路径:
from .models import MyModel from .messages import * to from apps.myapp.models import MyModel django.messages import *
MyAppConfig
class 中