在将 wagtail 添加到当前项目时,如何修复我的 Wagtail URL 命名空间和资源管理器?

How can I fix my Wagtail URL namespace and explorer when adding wagtail to a current project?

我的问题是我的 URL 出现在 mysite.com/test-news-1/ 而不是 mysite.com/news/test-news-1/

我使用 cookiecutter-django 开始了一个新项目。然后我想将 wagtail cms 添加到项目中并按照文档进行操作。

我在 /cms/ 而不是 /admin/ 上正常设置了 wagtail 管理页面 - http://docs.wagtail.io/en/v1.3.1/getting_started/integrating_into_django.html

我添加了几个应用程序只是为了练习和习惯wagtail,一个直接从wagtail博客示例中复制。这是我的问题开始的地方。

wagtail 管理资源管理器不会像在 wagtail 网站 https://wagtail.io/features/explorer/ 上那样列出我的应用程序,而只是说 "Welcome to your new Wagtail site!" 当我 select 添加子页面时,它允许我select 我设置的应用程序页面似乎符合我的模型。但是当我 post 某些东西并点击转到实时站点时,它会显示为 mysite.com/blog1/ 而不是 mysite.com/blog/blog1/

我相信我的问题是我不理解上面链接的文档页面的最后部分。它说,

Note that there’s one small difference when not using the Wagtail project template: Wagtail creates an initial homepage of the basic type Page, which does not include any content fields beyond the title. You’ll probably want to replace this with your own HomePage class - when you do so, ensure that you set up a site record (under Settings / Sites in the Wagtail admin) to point to the new homepage.

我尝试从文档页面添加主页模型,但这似乎根本没有帮助。

我很新手,这是我的urls.py文件,如果你需要看其他文件请告诉我。

urls.py    

from __future__ import unicode_literals

from django.conf import settings
from django.conf.urls import include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic import TemplateView
from django.views import defaults as default_views

from wagtail.wagtailadmin import urls as wagtailadmin_urls
from wagtail.wagtaildocs import urls as wagtaildocs_urls
from wagtail.wagtailcore import urls as wagtail_urls

urlpatterns = [
    url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name="home"),
    url(r'^about/$', TemplateView.as_view(template_name='pages/about.html'), name="about"),

    # Django Admin, use {% url 'admin:index' %}
    url(settings.ADMIN_URL, include(admin.site.urls)),

    # User management
    url(r'^users/', include("contestchampion.users.urls", namespace="users")),
    url(r'^accounts/', include('allauth.urls')),

    # Your stuff: custom urls includes go here

    # Wagtail cms
    url(r'^cms/', include(wagtailadmin_urls)),
    url(r'^documents/', include(wagtaildocs_urls)),
    url(r'', include(wagtail_urls)),

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

if settings.DEBUG:
    # This allows the error pages to be debugged during development, just visit
    # these url in browser to see how these error pages look like.
    urlpatterns += [
        url(r'^400/$', default_views.bad_request, kwargs={'exception': Exception("Bad Request!")}),
        url(r'^403/$', default_views.permission_denied, kwargs={'exception': Exception("Permission Denied")}),
        url(r'^404/$', default_views.page_not_found, kwargs={'exception': Exception("Page not Found")}),
        url(r'^500/$', default_views.server_error),
    ]

这两个 url 冲突 =

url(r'^$', TemplateView.as_view(template_name='pages/home.html'), name="home"),
url(r'', include(wagtail_urls)),

必须更改,否则 Django 将始终将 `yourdomain.com/' 的基数 url 解析为第一个条目。解决此问题的一种简单方法是更新第二个 -

url(r'^content/', include(wagtail_urls)),

现在可以在 yourdomain.com/content.

访问您的 Wagtail 根页面

至于 mysite.com/blog/blog1/ 不会出现,Url 会假设,从您的 Wagtail 根页面,有一个带有 slug 'blog' 的页面,然后是一个子页面与 slug blog1。默认情况下,您的 Wagtail 站点的树结构决定了 URL。如果您想覆盖它,则必须按照 here.

所述使用 RoutablePageMixin