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?
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_listcontext variables. However, the generic views provide the variablesobjectandobject_listas context. Therefore, you need to change your templates to match the new context variables. Go through your templates, and modify any reference tolatest_poll_listtoobject_list, and change any reference topolltoobject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With