Can't Get ListView to display result of SQL Query onto Custom Template

36 views
Skip to first unread message

Malik Rumi

unread,
Feb 25, 2016, 9:19:59 AM2/25/16
to Django users

Note- This question was originally posted on SO before I completely understood what my issue was. However, since editing it to reflect the true state of affairs, the silence over there has been deafening. I only mention that because some people don't like it when similar questions are posted to more than one forum by the same person, so now you know why I'm doing it. Thanks for understanding.


I can't get my subclass of ListView to display my content on my own template, even though it will display on the default code_list.html. My template does come up, but the queryset simply isn't there. I tried switching template names, but that didn't work. I've tried a wide variety of tweaks to context, but none of them worked. I tested my queryset in the shell, and it worked fine. Debug toolbar says my query executed. So it just seems to be getting it onto my template.


This shows a list of all my Code objects

class CodeListViewAll(ListView):

model = Code


but if I modify it in even the slightest way, it does not

class CodeListViewAll(ListView):

model = Code
template_name='statute.html'



I wrote a functional view to accomplish the same goal, but I got the same result with my statute.html – no data


statute.html

{% block content %}
<div class="row">
<div class="col-md-1">
    </div>
        <div class="col-md-10">
{% for i in codelist %} can you see this? < -- Yes, "can you see this?" displays
<li>{{ codelist.arrow }}</li>
{% endfor %}
        </div>
    <div class="col-md-1">
</div>
</div>
{% endblock content %}

Statute extends base, but since the inheritance seems to be working everywhere else on this template, I assume that is not an issue.

Vijay Khemlani

unread,
Feb 25, 2016, 9:24:23 AM2/25/16
to django...@googlegroups.com
<li>{{ codelist.arrow }}</li>


shouldn't you be using the for variable? something like

<li>{{ i.arrow }}</li>


--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fbd4faca-0b86-49fa-bc25-de1a7d93c58e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Malik Rumi

unread,
Feb 25, 2016, 9:39:44 AM2/25/16
to django...@googlegroups.com
I have been struggling with this all week. I posted to SO and got a lot of flack and downvoted - but no help. And FOUR MINUTES after I posted, you zeroed in on the problem. Yes, now my code displays on my own template. And you gave me no snark in the process. A true and helpful gentleman. Thank you, thank you, thank you. The only greater thing you could have done would be to give me the last 4 days back. 

p.s. - Nice hat!

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/o4UKSTBtwyg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.

To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages