Saturday, October 31, 2020

Problem with For and Forloop

Hello good, I have a problem using the for and for loop, what I want is that this process is repeated in all pages, so I put it in the base page.html. I want the last added in all pages like, in the blog, login and index. At this moment you can only see it in the index.

This is code inside the base:
<div>
                    <h3 class="blog-title">Latest Additions</h3>
                    {% for anime in num_blog %}
                    {% if forloop.revcounter %}
                    <a href="{% url 'anime-detail' anime.pk%}">
                        <img class="img-asides" src="{{ anime.image.url }}" alt=""></a>
                    <h3
                        style="text-align: center; max-width: 180px; font-size: 13px; margin-right: auto; margin-left: auto;">
                        {{ anime.tituloPag }}</h3>
                    {% endif %}
                    {% endfor %}
                </div>

This is the code in views.py:
def index(request):
    num_blog = Anime.objects.all()
    
    return render(
        request,
        'index.html',
        context={'num_blog':num_blog}
    )

def blog(request):
    num_blog = Anime.objects.all()

    return render(
        request,
        'blog.html',
        context={'num_blog':num_blog}
    )

But as I said you can only see the loop inside the index.html and not in the other pages, what can I do?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7b2c6cdf-1a38-4b66-8a24-3c473f8c281an%40googlegroups.com.

No comments:

Post a Comment