Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67441

ForeignKey don't show data

$
0
0

When I try to use foreignKey, html don't response

Models.py

class Home(models.Model):
book = models.ForeignKey(Book, verbose_name=(
    "book"), on_delete=models.CASCADE, related_name="book")

Views.py

def main(request):
   posts = Home.objects.all()
   return render(request, 'home/home-page.html', {'posts': posts})

HTML

{% for post in posts %} 
    {% for book in post.book.all %}
        {{ book }}
    {% endfor %}
{% endfor %}

What going wrong?


Viewing all articles
Browse latest Browse all 67441

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>