Reputation: 25472
Am working with django Publisher example, I want to list all the publishers in the db via my list_publisher.html template, my template looks like;
{% extends "admin/base_site.html" %}
{% block title %}List of books by publisher{% endblock %}
{% block content %}
<div id="content-main">
<h1>List of publisher:</h1>
{%regroup publisher by name as pub_list %}
{% for pub in pub_list %}
<li>{{ pub.name }}</li>
{% endfor %}
</div>
{% endblock %}
but when I run "http://127.0.0.1:8000/list_publisher/" the template just prints the page title with no error! What am I doing wrong?
Upvotes: 2
Views: 2960
Reputation: 17713
Good answer by VonC.
A quick and dirty way to look at pub_list is to stick [{{pub_list}}]
in your template. I put it in square brackets in case it's empty. BTW, you may get something that looks like [,,,,,]
. This is because object references are wrapped in <> and your browser is going WTF? Just do a View Source and you'll see the full result.
Upvotes: 0
Reputation: 1324128
A few suggestions:
{% block content %}{% endblock %}
section to be refine by your my list_publisher.html{%regroup publisher by name as pub_list %}{{ pub_list|length }}
. That should at least display the length of your list. If is is '0'... you know why it does not display anything{% regroup publisher|dictsort:"name" by name as pub_list %}
to be sureIf the length is '0', you have to make sure publisher is defined (has been initialized from the database), and sorted appropriately.
In other word, do you see anywhere (in your template or in the defined templates):
publisher = Publisher.objects.all().order_by("name")
?
(again, the order by name is important, to ensure your regroup tag works properly)
Upvotes: 3