1

单击发布或保存草稿时,我收到此错误 wagtail.core.models.Page.DoesNotExist: Page matching query does not exist. ,这只发生在旧页面上,新创建的页面能够被创建和保存而没有任何错误

注意:尽管我没有覆盖保存方法,但新页面没有子页面但试图找出导致此错误的原因任何建议或提示都会非常有帮助谢谢

这里是追溯:

wagtail.core.models.DoesNotExist
wagtail.core.models.Page.DoesNotExist: Page matching query does not exist.

Traceback (most recent call last)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/contrib/staticfiles/handlers.py", line 76, in __call__
return self.application(environ, start_response)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/wsgi.py", line 133, in __call__
response = self.get_response(request)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/base.py", line 130, in get_response
response = self._middleware_chain(request)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/exception.py", line 49, in inner
response = response_for_exception(request, exc)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/exception.py", line 103, in response_for_exception
response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/exception.py", line 138, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django_extensions/management/technical_response.py", line 37, in null_technical_500_response
six.reraise(exc_type, exc_value, tb)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/six.py", line 702, in reraise
raise value.with_traceback(tb)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/urls/__init__.py", line 127, in wrapper
return view_func(request, *args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/auth.py", line 172, in decorated_view
response = view_func(request, *args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/views/pages/edit.py", line 131, in dispatch
return super().dispatch(request)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/views/generic/base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/views/pages/edit.py", line 218, in post
return self.form_valid(self.form)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/views/pages/edit.py", line 238, in form_valid
return self.publish_action()
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/admin/views/pages/edit.py", line 286, in publish_action
revision.publish(
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/core/models.py", line 2972, in publish
page.save()
File "/home/oladhari/gounite-v2/GOunite/v2/home/models.py", line 98, in save
super().save(*args, **kwargs)
File "/usr/lib/python3.8/contextlib.py", line 75, in inner
return func(*args, **kwds)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/core/models.py", line 1028, in save
result = super().save(**kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/modelcluster/models.py", line 199, in save
getattr(self, relation).commit()
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/modelcluster/fields.py", line 202, in commit
item.delete()
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/wagtail/core/models.py", line 1094, in delete
return Page.objects.get(id=self.id).delete(*args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/oladhari/.virtualenvs/gounite/lib/python3.8/site-packages/django/db/models/query.py", line 429, in get
raise self.model.DoesNotExist(
wagtail.core.models.Page.DoesNotExist: Page matching query does not exist.
4

2 回答 2

0

引发错误的部分看起来像是模型中将一页与其他页相关联的代码。看到这一行:return Page.objects.get(id=self.id).delete(*args, **kwargs)?所以我认为我们需要知道什么是“项目”以及您保存的页面如何使用它们。

请发布您正在保存的页面的模型以及被引用为“项目”的页面

于 2021-02-08T23:57:41.127 回答
0

终于解决了,我们不应该将 ParentalKey 与 Page 模型一起使用(我们在 GOPart 模型中使用它,这是一个 Page 模型,将其更改为 ForeignKey 解决了错误,现在我们可以保存 HomePage

class MyModel(RoutablePageMixin, Page, Orderable):

    parent_page_types: list = []

    company = ParentalKey(
        "home.HomePage",
        on_delete=models.SET_NULL,
        verbose_name=_("Company"),
        null=True,
        blank=False,
    )

将其更改为:

class MyModel(RoutablePageMixin, Page):

    parent_page_types: list = []

    company = models.ForeignKey(
        "home.HomePage",
        on_delete=models.SET_NULL,
        verbose_name=_("Company"),
        null=True,
        blank=False,
    )

页面不能订购

于 2021-02-17T02:50:56.907 回答