views:

453

answers:

1

Not that level of failure indeed. I just completed the 4 part tutorial from djangoproject.com, my administration app works fine and my entry point url (/polls/) works well, with the exception that I get this http response:

No polls are available.

Even if the database has one registry. Entering with the admin app, the entry shows up the way it should be.

At the end of the tutorial, you change all your hard-coded views by replacing it for generic views on your URLconf. It's supossed that after all the modifications your urls.py ends up like this:

from django.conf.urls.defaults import *
from mysite.polls.models import Poll

info_dict = {
    'queryset': Poll.objects.all(),
}

urlpatterns = patterns('',
    (r'^$', 'django.views.generic.list_detail.object_list', info_dict),
    (r'^(?P<object_id>\d+)/$', 'django.views.generic.list_detail.object_detail', info_dict),
    url(r'^(?P<object_id>\d+)/results/$', 'django.views.generic.list_detail.object_detail', dict(info_dict, template_name='polls/results.html'), 'poll_results'),
    (r'^(?P<poll_id>\d+)/vote/$', 'mysite.polls.views.vote'),
)

Using these generic views, It'll be pointless to copy/paste my views.py file, I'll only mention that there's just a vote function (since django generic views do all the magic). My supposition is that the urls.py file needs some tweak, or is wrong at something In order to send that "No polls available." output at /polls/ url. My poll_list.html file looks like this:

{% if latest_poll_list %}
    <ul>
    {% for poll in latest_poll_list %}
        <li>{{ poll.question }}</li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}

It evals latest_poll_list to false, and that's why the else block is executed.

Can you give me a hand at this? (I searched at stackoverflow for duplicate question's, and even at google for this issue, but I couldn't find anything). Why do I get this message when I enter at http://127.0.0.1:8000/polls?

+9  A: 

You overlooked this paragraph in the 4. part of the tutorial:

In previous parts of the tutorial, the templates have been provided with a context that contains the poll and latest_poll_list context variables. However, the generic views provide the variables object and object_list as context. Therefore, you need to change your templates to match the new context variables. Go through your templates, and modify any reference to latest_poll_list to object_list, and change any reference to poll to object.

piquadrat
Thank you very much. It's hard to get familiar with django concepts. I was confused between the templates (.html's) and the views.py, I had only changed the context variables on the views, but not the ones in my templates.
Rigo Vides