jddg5wa
jddg5wa

Reputation: 45

Django Tutorial Part 3 - Index.html not doing anything

I am working on part 3 of the django tutorial and after setting up index.html and views although nothing is happening.

This is what the tutorial says should be happening, "Load the page by pointing your browser at “/polls/”, and you should see a bulleted-list containing the “What’s up” question from Tutorial 1. The link points to the question’s detail page."

The list doesn't show up, all I see if "Hello, world. You're at the polls index."

These are my files:

from django.http import HttpResponse
from django.shortcuts import render

from polls.models import Question


def index(request):
    latest_question_list = Question.objects.order_by('-pub_date')[:5]
    context = {'latest_question_list': latest_question_list}
    return render(request, 'polls/index.html', context)


def index(request):
    return HttpResponse("Hello, world. You're at the polls index.")

def detail (request, question_id):
    return HttpResponse("You're looking at question %s." % question_id)

def results(request, question_id):
    response = "Your looking at the results of question %s."
    return HttpResponse(response % question_id)

def vote(request, question_id):
    return HttpResponse("You're voting on question %s." % question_id)

Views.py

{% if latest_question_list %}
    <ul>
    {% for question in latest_question_list %}
        <li><a href="/polls/{{ question.id }}/">{{ question.question_text }}</a></li>
    {% endfor %}
    </ul>
{% else %}
    <p>No polls are available.</p>
{% endif %}

Index.Html (located in mysite/polls/templates/polls)

from django.conf.urls import patterns, url

from polls import views

urlpatterns = patterns('',
    # ex: /polls/
    url(r'^$', views.index, name='index'),
    # ex: /polls/5/
    url(r'^(?P<question_id>\d+)/$', views.detail, name='detail'),
    # ex: /polls/5/results/
    url(r'^(?P<question_id>\d+)/results/$', views.results, name='results'),
    # ex: /polls/5/vote/
    url(r'^(?P<question_id>\d+)/vote/$', views.vote, name='vote'),
)

Urls.py

I'm not sure why nothing is happening, what I may be doing wrong. Any suggestions? Thanks!

Upvotes: 0

Views: 1395

Answers (1)

dylrei
dylrei

Reputation: 1736

The problem is you have more than one index method. The first one looks good, but the second one is replacing the behavior of the first one.

Upvotes: 4

Related Questions