ichthyocentaurs
ichthyocentaurs

Reputation: 2175

Template does not show html content

TemplateSyntaxError at /deals/amp-stories Invalid block tag on line 576: 'else', expected 'empty' or 'endfor'. Did you forget to register or load this tag?

Request Method: GET Request

URL: http://localhost:8001/deals/amp-stories?card_ids=1 Django

Version: 2.2.7 Exception Type: TemplateSyntaxError Exception Value:
Invalid block tag on line 576: 'else', expected 'empty' or 'endfor'. Did you forget to register or load this tag?

I am trying to create a view that will load a template view in django and I am getting the above error.

<body>
    <!-- supports-landscape -->
    {% if card_list %}
        <amp-story standalone title="Best islands to visit from Guernsey" publisher="add here" publisher-logo-src="add here" poster-portrait-src="add-logo" poster-square-src="add-logo-here" poster-landscape-src="add-logo-here" supports-landscape>
            {% for card in card_list %}
                <amp-story-page id="slide_3" class="i-amphtml-element i-amphtml-layout-container i-amphtml-layout i-amphtml-story-page-loaded" i-amphtml-layout="container" aria-label="null" distance="0" i-amphtml-visited="" active="">
                    <amp-story-grid-layer template="fill" class="zoomIn i-amphtml-element i-amphtml-layout-container i-amphtml-story-layer i-amphtml-story-grid-template-fill i-amphtml-layout" i-amphtml-layout="container">
                        <amp-img src="{{card.card_image}}" width="1080" height="1920" class="i-amphtml-element i-amphtml-layout-fixed i-amphtml-layout-size-defined i-amphtml-layout" i-amphtml-layout="fixed" style="width: 1080px; height: 1920px; --loader-delay-offset:6ms !important;" i-amphtml-auto-lightbox-visited="">
                            <img decoding="async" src="{{card.card_image}}" class="i-amphtml-fill-content i-amphtml-replaced-content">
                        </amp-img>
                    </amp-story-grid-layer>
                    <div class="i-amphtml-story-spinner" aria-hidden="true" aria-label="Loading video">
                        <div class="i-amphtml-story-spinner-container">
                            <div class="i-amphtml-story-spinner-layer">
                                <div class="i-amphtml-story-spinner-circle-clipper left"></div>
                                <div class="i-amphtml-story-spinner-circle-clipper right"></div>
                            </div>
                        </div>
                    </div>
                </amp-story-page>
            (% endfor %)
    {% else %}
        <p>There are no cards in the collection.</p>
    {% endif %}
    </amp-story>

</body>

</html>

views.py

class StoryList(ListView):
    model = Card
    context_object_name = "all_cards"
    template_name = "card_list.html"

urls.py

urlpatterns = [    
    path('amp-stories', StoryList.as_view(), name='ampstories'),
]

models.py

class Card(models.Model):
    tag = models.ManyToManyField(CardTag)
    card_name = models.CharField(max_length=200)
    card_image =models.ImageField(upload_to='slides')
    card_createdate = models.DateTimeField(auto_now=True)


    class Meta:
        ordering = ['card_name']

    def __str__(self):
        return self.card_name

    def slide_thumbnail(self):
        return html.format_html(u'<img src="'+settings.HOSTNAME+'%s" width="100px"/>' % (self.card_image.url))

    slide_thumbnail.short_description = 'Thumbnail'

Upvotes: 1

Views: 213

Answers (1)

willeM_ Van Onsem
willeM_ Van Onsem

Reputation: 476729

In your template you wrote (% endfor %) instead of {% endfor %}. By using round parenthesis ((% … %)) instead of curly brackets ({% … %}), the template engine does not see this as a template tag, and thus still things you are in the {% for … %} tag.

You thus should rewrite your template to use {% endfor %} instead of (% endfor %).

Upvotes: 1

Related Questions