While I was following through on the instructions on this page Writing your first Django app, I did all that is expected off me until I updated my views.py, passing question_text as a parametre, which as expected is supposed to substistute the %s
placeholder, but the question.text is not being shown on my page. Even after creating a template as instructed, I only get a list of bullets and no content.
Below are my codes and the responses I got
Views.py
`from django.shortcuts import render
from django.http import HttpResponse
from .models import Question
from django.template import loader
Create your views here.
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 are looking at %s ", question_id)
def results(request, question_id):
response = "You are looking at the results of question %s "
return HttpResponse(response, question_id)
def vote(request, question_id):
return HttpResponse("You are voting on question %s ", question_id)`
Urls.py
`from django.shortcuts import render
from django.http import HttpResponse
from .models import Question
from django.template import loader
Create your views here.
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 are looking at %s ", question_id)
def results(request, question_id):
response = "You are looking at the results of question %s "
return HttpResponse(response, question_id)
def vote(request, question_id):
return HttpResponse("You are voting on question %s ", question_id)`
index.html
`
Questions
{% if latest_question_list %}-
{% for question in latest_question_list %}
- {{ question.text }} {% endfor %}
No polls are available.
{% endif %} `My response on the webpage
●
●
●
●
●