user5569788
user5569788

Reputation:

Wagtail template not loading

I'm trying to set up a small Wagtail blog, it's inside of an existing Django project. I've tried following the official wagtail documentation but I'm failing to view my template, instead I'm greeted with "Welcome to your new Wagtail site!" The tree for my blog app looks like this

    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

All the other files I refrence here are from this tree. The models.py looks like this

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 model app

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 %}

and finally the urls.py in my project root

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')),

]

Sorry for posting all this code, but I don't know where the error could be. Thank you for all replies! From what I gather from the documentation Wagtail should fond blog_page.html because class BlogPage looks for a "blog_page" view name.

Upvotes: 1

Views: 1627

Answers (1)

gasman
gasman

Reputation: 25227

By creating the BlogPage class and template, you've defined BlogPage as a new page type, but you haven't created an actual page of that type yet. You now need to go into the Wagtail admin at /cms, and create and publish a new page alongside the existing "Welcome to your new Wagtail site!" page. You then need to go to Settings -> Sites and update the record to point to that new page.

Upvotes: 3

Related Questions