Yet Another Noob here...

I've searched f the prblem I have. I found some but no post helped.

I followed the tutorial step by step. I had no problem until generic
views.

(Windows XP - Django 1.1.1 - python 2.6.4.8 )

Here's the directory hierarchy

E:\djanggoHttpDoc\mysite - settings.py, manage.py, urls.py,
__init__.py

E:\djanggoHttpDoc\mysite\polls - admin.py, models.py, tests.py,
urls.py, views.py, __init__.py

E:\djanggoHttpDoc\mysite\db - sqlite3.db

E:\djanggoHttpDoc\mytemplates\admin\base_site.html

E:\djanggoHttpDoc\mytemplates\polls - detail.html, index.html,
poll_list.html, results.html

I know I didn't renamed detail to poll_detail.html etc.

However, I only wanted to check http://127.0.0.1:8000/polls/ first.
but it showed

No polls are available

I DO have poll and choice data in db, and it worked with the
templates.

What could be the problem?

polls/urls.py
=======================================
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'),
)

==============================================
polls/views.py
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseRedirect, HttpResponse
from django.core.urlresolvers import reverse
from mysite.polls.models import Choice, Poll




def detail(request, poll_id):
    p = get_object_or_404(Poll, pk=poll_id)
    return render_to_response('polls/detail.html', {'poll': p})

def vote(request, poll_id):
    p = get_object_or_404(Poll, pk=poll_id)
    try:
        selected_choice = p.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        # Redisplay the poll voting form.
        return render_to_response('polls/detail.html', {
            'poll': p,
            'error_message': "You didn't select a choice.",
        })
    else:
        selected_choice.votes += 1
        selected_choice.save()
        # Always return an HttpResponseRedirect after successfully
dealing
        # with POST data. This prevents data from being posted twice
if a
        # user hits the Back button.
        return
HttpResponseRedirect(reverse('mysite.polls.views.results',
args=(p.id,)))

def results(request, poll_id):
    p = get_object_or_404(Poll, pk=poll_id)
    return render_to_response('polls/results.html', {'poll': p})

========================================================

If you need to see other files, please let me know.

Thank you

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to