Views not rendering properly

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-- it prints the text and the %s. Even after creating a template as instructed, I only get a list of bullets and no content. But when I delete all the questions in the database, the else statement shows.

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

Questions

{% if latest_question_list %} {% else %}

No polls are available.

{% endif %} `

My response on the webpage
Question




What happens when you change the template expression {{ question.text }} to {{ question.question_text }}?

It looks like the model doesn’t have the text property, but question_text instead:

from django.db import models


class Question(models.Model):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')


class Choice(models.Model):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)

I hope it helps :slight_smile: