You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Wagtail教程中FieldPanel富文本欢迎消息未显示问题咨询

Troubleshooting Missing "Welcome to our new site!" Message in Wagtail

Hey there! Let's work through why that bold welcome message isn't showing up, even after running makemigrations and migrate. Here are the key areas to check step by step:

1. Verify Your HomePage Model Setup

That welcome message is almost always tied to a field in your HomePage model (usually in home/models.py). First, make sure your model includes a field to store this content—most Wagtail tutorials use a RichTextField for this purpose.

Check if your model looks something like this:

from wagtail.models import Page
from wagtail.fields import RichTextField
from wagtail.admin.panels import FieldPanel

class HomePage(Page):
    # This field holds the welcome message; the default value auto-populates it
    body = RichTextField(blank=True, default="<b>Welcome</b> to our new site!")

    # Add the field to the admin edit panel so you can modify it later
    content_panels = Page.content_panels + [
        FieldPanel('body'),
    ]
  • If you didn't add this body field (or used a different name), the message has nowhere to live in your database.
  • If you added the field without the default parameter, the field will be empty unless you manually enter the message in the Wagtail admin.

2. Ensure You've Created & Published a HomePage Instance

Wagtail doesn't automatically generate a homepage for you—you need to set this up in the admin dashboard:

  • Go to your Wagtail admin (typically at /admin), log in, and navigate to Pages > Add page.
  • Select your HomePage type, fill in required fields like title, and check if the body field already has the welcome message (thanks to the model's default value). If not, paste <b>Welcome</b> to our new site! into it.
  • Publish the page, then set it as your site's root page: Go to Settings > Sites, edit your site, and select your new HomePage as the "Root page".

3. Check Your Template is Rendering the Field

Even if the data exists in your model, your template needs to display it. Open your homepage template (usually templates/home/home_page.html) and confirm it includes the field:

{% extends "base.html" %}

{% block content %}
    <!-- This line renders the body field containing your welcome message -->
    {{ page.body }}
{% endblock %}
  • If you used a different field name (like content instead of body), replace page.body with your field's actual name.
  • Ensure the template follows Wagtail's default naming convention: appname/modelname.html (so home/home_page.html works for a HomePage model in the home app).

4. Double-Check Migrations & Data

You mentioned running makemigrations and migrate, but let's confirm the changes took effect:

  • Open a Django shell with python manage.py shell and run these commands:
    from home.models import HomePage
    # Fetch the first homepage instance
    homepage = HomePage.objects.first()
    # Print the body content to verify it exists
    print(homepage.body)
    
    • If the output is empty, either the model field wasn't added correctly, or you didn't save the message in the admin.
    • If the output shows the bold welcome message, the issue is definitely in your template not rendering it.

5. Clear Caches (Just in Case)

Occasionally, Wagtail or browser caching can block new content from appearing:

  • In the Wagtail admin, go to your homepage and click Publish again (even if it's already published—this refreshes the system cache).
  • Clear your browser's cache or open the page in an incognito window to rule out client-side caching.

内容的提问来源于stack exchange,提问作者notionquest

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:29:40