Wagtail (Django) does not show blocked images. (Character only)

Asked 2 years ago, Updated 2 years ago, 122 views

Question details

We are developing web applications using wagtail.For content display, we block names, links, etc., import them into content models, and consider HTML output.Other information such as the name is displayed, but only images are not displayed.There are no errors and the name of the image is displayed as a character, so I think there is no problem.I've tried and tried, but I don't know, so I'd appreciate your help.

Code

The following are the codes that might apply:Close to the front end from the top to bottom to bottom.
First, we block the elements that we want to insert on blocks.py and model them for output on models.py.The process is to HTML the block with article_block.html and put it on the ContentIndex page.

I tried many times to move my existing files and look at the documents, but I couldn't.Thank you for your cooperation.

blocks.py

class ArticleBlock (blocks.StructBlock):
    article_title=blocks.CharBlock(require=True,help_text='add content title')
    thumbnail=ImageChooserBlock (required=True)
    heading=blocks.TextBlock(require=True,help_text='add additional text')
    article_link=blocks.URLBlock(required=True)

    class Meta:
        template="streams/article_block.html"
        icon="edit"
        label="article"

models.py

class ContentIndexPage(Page):
    template="contents/content_index.html"

    header=models.ForeignKey(
        HeaderPage,
        null = True,
        blank = True,
        on_delete=models.SET_NULL,
        related_name = '+')

    page_title=models.CharField(max_length=100, blank=False, null=True)

    content=StreamField(
        [
            ("article_info", blocks.ArticleBlock())
        ],
        null = True,
        blank = True,
    )

    content_panels = Page.content_panels+[
        SnippetChooserPanel('header'),
        FieldPanel('page_title',
        StreamFieldPanel ("content"),
    ]

    def get_context(self, request, *args, **kwargs):
        context=super().get_context(request, *args, **kwargs)
        context["articles" = ContentIndexPage.objects.live().public()
        return context

    class Meta:
        verbose_name = "Content Page"
        verbose_name_plural="Content Pages"

article_block.html

{%loadwagtailimages_tagswagtailcore_tags%}

<div class="container mb-sm-5mt-sm-5">
    <div class="row">
        {% US>for article in articles%}
            {% image self.thumbnail fill-300x200asimg%}
                <img src="{{img.article_link}}" alt="{img.alt}}" class="img-thumbnail">
                <a href="{{self.article_link}}">
                    <h2>{{self.article_title}}</h2>
                </a>
                <p>{{self.heading}}</p>
        {% endfor%}
    </div>

content_index.html

{%extends"base.html"%}
{% loadwagtailcore_tags%}

{% US>block content%}
<div class="jumbotron">
    <div class="container">
        <div class="row">
            <div class="col-sm-12 text-center">
                <h1class="display-4">{{self.page_title}}</h1>
            </div>
        </div>
    </div>
</div>

{% for block in page.content%}
    {% include_block block%}
{% endfor%}

{% endblock content%}

python html django

2022-09-30 19:28

1 Answers

Successfully displayed in self.article.article_title


2022-09-30 19:28

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.