Friday, August 11, 2017

Tutorial writing views help

I am currently up to the "writing views" part of the tutorial and just wrote the polls/index.html template. I updated the view in polls/view.py as such:

from django.http import HttpResponse
from django.template import loader

from .models import Question

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

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

def results(request,question_id):
    response = "You're 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)




I ran  $python manage.py check and the system identified no issues.
When I open the page 127.0.0.1:8000/polls/ I  get a blank page instead of a bulleted list of the questions I created.

Also I get the following error when I load 127.0.0.1:8000/polls/.

Page not found (404)

Request Method:GET
Request URL:http://127.0.0.1:8000/

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

  1. ^polls/
  2. ^admin/

The empty path didn't match any of these.


mysite.urls


from django.conf.urls import url, include

from django.contrib import admin



urlpatterns = [

    url(r'^polls/', include('polls.urls')),

    url(r'^admin/', admin.site.urls),

]


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/452bc401-661b-4edd-950c-7ce90e0814e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment