Wagtail模板没有加载

时间:2017-11-21 11:03:35

标签: django wagtail

我正在尝试建立一个小的Wagtail博客,它在一个现有的Django项目中。 我已经尝试过遵循官方的wagtail文档,但是我没有查看我的模板,相反,我迎来了“欢迎来到你的新Wagtail网站!” 我的博客应用程序的树看起来像这样

    blog
├── admin.py
├── apps.py
├── __init__.py
├── migrations
│   ├── 0001_initial.py
│   ├── 0002_auto_20171121_0949.py
│   ├── __init__.py
│   └── __pycache__
│       ├── 0001_initial.cpython-36.pyc
│       ├── 0002_auto_20171121_0949.cpython-36.pyc
│       └── __init__.cpython-36.pyc
├── models.py
├── __pycache__
│   ├── admin.cpython-36.pyc
│   ├── __init__.cpython-36.pyc
│   ├── models.cpython-36.pyc
│   └── urls.cpython-36.pyc
├── templates
│   └── blog
│       └── blog_page.html
├── tests.py
├── urls.py
└── views.py

我在这里引用的所有其他文件都来自这棵树。 models.py看起来像这样

from wagtail.wagtailcore.models import Page
from wagtail.wagtailcore.fields import RichTextField
from wagtail.wagtailadmin.edit_handlers import FieldPanel


class BlogPage(Page):
    intro = RichTextField(blank=True)
    body = RichTextField(blank=True)

    content_panels = Page.content_panels + [
        FieldPanel('body', classname="full"),
    ]

来自模型应用的urls.py

from wagtail.wagtailadmin import urls as wagtailadmin_urls
from wagtail.wagtaildocs import urls as wagtaildocs_urls
from wagtail.wagtailcore import urls as wagtail_urls
from django.conf.urls import url, include
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    url(r'^cms/', include(wagtailadmin_urls)),
    url(r'^documents/', include(wagtaildocs_urls)),
    #from /blog is where our blog will reside
    url(r'^', include(wagtail_urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

blog_page.html

{% extends "base.html" %}

{% load wagtailcore_tags %}

{% block body_class %}template-blogindexpage{% endblock %}

{% block content %}
    <h1>{{ page.title }}</h1>

    <div class="Why is this not working?">{{ page.intro|richtext }}</div>

    {% for post in page.get_children %}
        <h2><a href="{% pageurl post %}">{{ post.title }}</a></h2>
        {{ post.specific.intro }}
        {{ post.specific.body|richtext }}
    {% endfor %}
    <h1>Hello world!</h1>

{% endblock %}

最后是我的项目根目录中的urls.py

from django.conf.urls import include, url
from django.contrib import admin

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^', include('homepage.urls')),
    url(r'^blog/', include('blog.urls')),

]

很抱歉发布所有这些代码,但我不知道错误的位置。谢谢你的回复!从我从文档中收集的Wagtail应该喜欢blog_page.html,因为类BlogPage查找“blog_page”视图名称。

1 个答案:

答案 0 :(得分:0)

通过创建BlogPage类和模板,您已将BlogPage定义为新页类型,但尚未创建该类型的实际页面。您现在需要进入/cms的Wagtail管理员,并在现有的“欢迎来到您的新Wagtail网站”旁边创建和发布新页面!页。然后,您需要转到设置 - &gt;站点并更新记录以指向该新页面。