I am trying to integrate wagtail into an existing django project, but I am getting the above error when I add a child page.
In my settings I have followed the instructions so:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'whitenoise.runserver_nostatic',
'home',
'news',
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail',
'modelcluster',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django_permissions_policy.PermissionsPolicyMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'wagtail.contrib.redirects.middleware.RedirectMiddleware',
]
my project urls:
from django.urls import include, path
from django.conf import settings
from django.conf.urls.static import static
from django.urls import reverse
from wagtail.admin import urls as wagtailadmin_urls
from wagtail import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls
urlpatterns = [
path('', include('home.urls')),
path('news/', include('news.urls')),
path('cms/', include(wagtailadmin_urls)),
path('documents/', include(wagtaildocs_urls)),
path('news/', include(wagtail_urls)),
] static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
my news urls:
from django.urls import path
from .views import news_article_detail
urlpatterns = [
path('news/<int:pk>/', news_article_detail, name='news_article_detail'),
]
in my news view:
from django.shortcuts import render
from .models import NewsArticlePage
#import pdb; pdb.set_trace()
def news_article_detail(request, pk):
news_article = NewsArticlePage.objects.get(pk=pk)
return render(request, 'news/news_page.html', {'news_article': news_article})
and my model:
from django.db import models
from wagtail.core.models import Page
from wagtail.admin.edit_handlers import FieldPanel
from wagtail.core.fields import RichTextField
class NewsArticlePage(Page):
article_body = RichTextField(blank=True)
content_panels = Page.content_panels [
FieldPanel('article_body'),
]
template = "news/news_page.html"
and in my template:
{% extends "base.html" %}
{% block content %}
<h1>{{ page.title }}</h1>
{{ page.article_body|richtext }}
{% endblock %}
I have also added the root page, made sure that the url's are pointing to the correct place, made migrations & migrated but still I get the same error. So when I go to localhost/cms in the backend I have a page set up, when I go to add a child page I get the error, I tried the python manage.py fixtree but I still get the error, here is the stack trace:
nvironment:
Request Method: POST Request URL: http://127.0.0.1:7000/cms/pages/add/news/newsarticlepage/2/
Django Version: 3.2.4
Python Version: 3.11.1
Installed Applications:
['django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.humanize',
'whitenoise.runserver_nostatic',
'accounts',
'compressor',
'corsheaders',
'home',
'news',
'taggit',
'widget_tweaks',
'sass_processor',
'wagtail.contrib.forms',
'wagtail.contrib.redirects',
'wagtail.embeds',
'wagtail.sites',
'wagtail.users',
'wagtail.snippets',
'wagtail.documents',
'wagtail.images',
'wagtail.search',
'wagtail.admin',
'wagtail',
'modelcluster']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django_permissions_policy.PermissionsPolicyMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'wagtail.contrib.redirects.middleware.RedirectMiddleware']
Traceback (most recent call last):
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func
response = view_func(request, *args, **kwargs)
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\wagtail\admin\urls\__init__.py", line 170, in wrapper
return view_func(request, *args, **kwargs)
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\wagtail\admin\auth.py", line 182, in decorated_view
response = view_func(request, *args, **kwargs)
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\django\views\generic\base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\wagtail\admin\views\pages\create.py", line 119, in dispatch
return super().dispatch(request)
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\django\views\generic\base.py", line 98, in dispatch
return handler(request, *args, **kwargs)
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\wagtail\admin\views\pages\create.py", line 132, in post
return self.form_valid(self.form)
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\wagtail\admin\views\pages\create.py", line 148, in form_valid
return self.save_action()
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\wagtail\admin\views\pages\create.py", line 170, in save_action
self.parent_page.add_child(instance=self.page)
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\treebeard\mp_tree.py", line 1089, in add_child
return MP_AddChildHandler(self, **kwargs).process()
File "C:\Users\sesa301575\sites\Django.Azure\venv\Lib\site-packages\treebeard\mp_tree.py", line 383, in process
newobj.path = self.node.get_last_child()._inc_path()
Exception Type: AttributeError at /cms/pages/add/news/newsarticlepage/2/
Exception Value: 'NoneType' object has no attribute '_inc_path'
CodePudding user response:
'NoneType' object has no attribute '_inc_path'
usually indicates that the internal fields (path
, depth
, numchild
) defined by the django-treebeard library for keeping track of child counts in the page tree have become inconsistent. It's unclear what might have caused that here, but running ./manage.py fixtree
should fix it.