Got it, shouldn't be hitting /polls

Since we put in the object_id
Alex

On May 1, 8:57 am, arfinsd <alex.r.fergu...@gmail.com> wrote:
> Have a newbie question. I'm stuck on the tutorial and keep getting a
> 404 error when I try to hit:http://127.0.0.1:8000/polls
>
> My files are listed below, does anyone see something that I'm doing
> wrong?
>
> URLS.py
>
> #----------------------------------
> # Uncomment the next two lines to enable the admin:
> # This maps URL roots to applications
> #----------------------------------
> from django.contrib import admin
> admin.autodiscover()
>
> from django.conf.urls.defaults import *
> from mysite.polls.models import Poll
>
> info_dict = {
>     'queryset': Poll.objects.all(),
>
> }
>
> urlpatterns = patterns('',
>     # Example:
>     # (r'^mysite/', include('mysite.foo.urls')),
>
>     # Uncomment the admin/doc line below and add
> 'django.contrib.admindocs'
>     # to INSTALLED_APPS to enable admin documentation:
>     # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
>
>     # Uncomment the next line to enable the admin:
>     (r'^admin/(.*)', admin.site.root),
>
>     # Add Polls Views (Design URLs)
>     # Define them in views
>     # Add templates
>     (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'),
> )
>
> VIEWS.py
>
> # Create your views here.
> from mysite.polls.models import Choice, Poll
> from django.shortcuts import render_to_response, get_object_or_404
> from django.http import HttpResponseRedirect
> from django.core.urlresolvers import reverse
>
> def vote(request, object_id):
>     p = get_object_or_404(Object, pk=object_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/poll_detail.html', {
>             'object': p,
>             'error_message': "You didn't select a choice.",
>         })
>     else:
>         selected_choice.votes += 1
>         selected_choice.save()
>         return HttpResponseRedirect(reverse('poll_results', args=
> (p.id,)))
>
> POLL_DETAIL.html
>
> <h1>{{ object.question }}</h1>
>
> {% if error_message %}<p><strong>{{ error_message }}</strong></p>{%
> endif %}
>
> <form action="vote/" method="post">
> {% for choice in object.choice_set.all %}
>     <input type="radio" name="choice" id="choice{{ forloop.counter }}"
> value="{{ choice.id }}" />
>     <label for="choice{{ forloop.counter }}">{{ choice.choice }}</
> label><br />
> {% endfor %}
> <input type="submit" value="Vote" />
> </form>
>
> POLL_LIST.html
>
> {% if object_list %}
>     <ul>
>     {% for object in object_list %}
>         <li>{{ object.question }}</li>
>     {% endfor %}
>     </ul>
> {% else %}
>     <p>No polls are available.</p>
> {% endif %}
>
> RESULTS.html
>
> <h1>{{ object.question }}</h1>
>
> <ul>
> {% for choice in object.choice_set.all %}
>     <li>{{ choice.choice }} -- {{ choice.votes }} vote{{ choice.votes|
> pluralize }}</li>
> {% endfor %}
> </ul>
>
> VOTE.html
>
> {{object}}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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