首页 > 解决方案 > 在页面上使用 wagtailtrans 包时内容不显示

问题描述

在我的 models.py 文件中,我定义了要添加翻译的StandardPage 类enter code here。在这个类中,我定义了这些:

class StandardPage(TranslatablePage,Page):

    introduction = models.TextField(
        help_text='Text to describe the page',
        blank=True)
    image = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+',
        help_text='Landscape mode only; horizontal width between 1000px and 3000px.'
    )
    video_url = models.URLField(null=True,blank=True)
    body = StreamField([
        ( 'main_content',blocks.ListBlock(BaseStreamBlock()  ,label = 'content') )]
        , blank=True,
           null=True,
         verbose_name="Page body" )

    content_panels = Page.content_panels + [
        FieldPanel('introduction', classname="full"),
        StreamFieldPanel('body'),
        ImageChooserPanel('image'),
        FieldPanel('video_url'),   ]

 @property
 def standard_page(self):
    return self.get_parent().specific

 def get_context(self, request):
    language = request.LANGUAGE_CODE
    standard_page = request.site.standard_page
    pages = TranslatablePage.objects.live().filter(language__code=language).specific().child_of(standard_page)
    context['pages'] = self.standard_page
    return context

虽然模板 base.html 包含:

{% load i18n %}
{% load wagtailtrans_tags wagtailcore_tags  wagtailuserbar  %}
{% load static %}
<!DOCTYPE html>
<html class="no-js">
    <head>
        <meta charset="utf-8" />
        <title>
            {% block title_suffix %}
                {% if self.seo_title %}{{ self.seo_title }}{% else %}{{ self.title }}{% endif %}
            {% endblock %}
        </title>
        <meta name="description" content="" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        {# Global stylesheets #}
        <link rel="stylesheet" type="text/css" href="{% static 'css/mysite.css' %}">
<link href="{% static 'css/bootstrap.min.css' %}" type="text/css" rel="stylesheet" />
<link href="{% static 'fonts/font-awesome-4.7.0/css/font-awesome.min.css' %}" type="text/css" rel="stylesheet" />
<link href="{% static 'css/streamfields.css' %}" type="text/css" rel="stylesheet" />

        {% block extra_css %}
            {# Override this in templates to add extra stylesheets #}
        {% endblock %}
    </head>
    <body class="{% block body_class %}{% endblock %}">
        {% wagtailuserbar %}
{% get_translations page homepage_fallback=False include_self=False as translations %}
{% for language, page in translations.items %}
<link rel="alternate" href="{{ page.full_url }}" hreflang="{{ language.code }}">
{% endfor %}
        {% block content %}
        {% endblock %}
        {# Global javascript #}

        <script type="text/javascript" src="{% static 'js/mysite.js' %}"></script>
        <script type="text/javascript" src="{% static 'js/jquery-2.2.3.min.js' %}"></script>
<script type="text/javascript" src="{% static 'js/bootstrap.min.js' %}"></script>

        {% block extra_js %}
            {# Override this in templates to add extra javascript #}
        {% endblock %}
    </body>
</html>

我的模板“standard_page.html”包含:

{% extends "base.html" %}
{% load wagtailcore_tags wagtailimages_tags %}
 {% block content%}
{% include "base/include/header.html" %}
    <div class="container">
        <div class="row">
            <div class="col-md-7">
                {{ page.body }}
            </div>
 </div>
        </div>
{% endblock  %}

未在页面上呈现内容。它显示欢迎来到您的新 Wagtail 网站!即使我发布了特定页面的所有语言。但是页面的标题以不同的语言显示,提到我是 django 和 wagtail 的新手。如何纠正这个,没有得到。有什么帮助吗?

标签: djangodjango-templateswagtail

解决方案


推荐阅读