我分叉了https://github.com/arneb/django-messages/并把它放在我的仓库中:https://github.com/mike-johnson-jr/django-messages/
当我使用该包时,我在标题中收到错误。完全追溯:
Traceback (most recent call last):
File "manage.py", line 15, in
execute_from_command_line(sys.argv)
File "/home/michael/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/home/michael/.local/lib/python3.6/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/home/michael/.local/lib/python3.6/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/michael/.local/lib/python3.6/site-packages/django/apps/registry.py", line 112, in populate
app_config.import_models()
File "/home/michael/.local/lib/python3.6/site-packages/django/apps/config.py", line 198, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "/home/michael/.local/lib/python3.6/site-packages/django_messages/models.py", line 48, in
class Message(models.Model):
File "/home/michael/.local/lib/python3.6/site-packages/django_messages/models.py", line 87, in Message
get_absolute_url = reverse(get_absolute_url)
File "/home/michael/.local/lib/python3.6/site-packages/django/urls/base.py", line 90, in reverse
return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/home/michael/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 562, in _reverse_with_prefix
self._populate()
File "/home/michael/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 413, in _populate
for url_pattern in reversed(self.url_patterns):
File "/home/michael/.local/lib/python3.6/site-packages/django/utils/functional.py", line 37, in get
res = instance.__dict__[self.name] = self.func(instance)
File "/home/michael/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/michael/.local/lib/python3.6/site-packages/django/utils/functional.py", line 37, in get
res = instance.__dict__[self.name] = self.func(instance)
File "/home/michael/.local/lib/python3.6/site-packages/django/urls/resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "/home/michael/projects/datafix/datafix/urls.py", line 65, in
path('messages/', include('django_messages.urls')),
File "/home/michael/.local/lib/python3.6/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 994, in _gcd_import
File "", line 971, in _find_and_load
File "", line 955, in _find_and_load_unlocked
File "", line 665, in _load_unlocked
File "", line 678, in exec_module
File "", line 219, in _call_with_frames_removed
File "/home/michael/.local/lib/python3.6/site-packages/django_messages/urls.py", line 4, in
from django_messages.views import *
File "/home/michael/.local/lib/python3.6/site-packages/django_messages/views.py", line 11, in
from django_messages.models import Message
ImportError: cannot import name 'Message'
这里是我的django_messages.models代码:
@python_2_unicode_compatible
class Message(models.Model):
"""
A private message from user to user
"""
subject = models.CharField(_("Subject"), max_length=140)
body = models.TextField(_("Body"))
sender = models.ForeignKey(AUTH_USER_MODEL, related_name='sent_messages', verbose_name=_(
"Sender"), on_delete=models.SET_NULL)
recipient = models.ForeignKey(AUTH_USER_MODEL, related_name='received_messages',
null=True, blank=True, verbose_name=_("Recipient"), on_delete=models.SET_NULL)
parent_msg = models.ForeignKey('self', related_name='next_messages', null=True,
blank=True, verbose_name=_("Parent message"), on_delete=models.SET_NULL)
sent_at = models.DateTimeField(_("sent at"), null=True, blank=True)
read_at = models.DateTimeField(_("read at"), null=True, blank=True)
replied_at = models.DateTimeField(_("replied at"), null=True, blank=True)
sender_deleted_at = models.DateTimeField(
_("Sender deleted at"), null=True, blank=True)
recipient_deleted_at = models.DateTimeField(
_("Recipient deleted at"), null=True, blank=True)
objects = MessageManager()
import 出错一般就一个问题:循环引用,你前面定义message model的代码逻辑间接依赖import model
错误出现在我的django_messages.models.Message代码中,get_absolute_url()很不稳定。
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。