Michael Cocca
Michael Cocca

Reputation: 11

Django Template not displaying model data

I've looked through different tutorials and Stack Overflow questions and I'm not sure why I'm still running into this issue:

I am running into an issue with displaying my model data onto my template, I can see that the python code is executing, but no matter what I've tried I can't get my data to come through, my relevant code snippets are below:

models.py

class GoogleData(models.Model):
    placeID = models.CharField(max_length=999)
    name = models.CharField(max_length=200)
    phoneNumber =  models.CharField(max_length=800)
    busAddress = models.CharField(max_length=2000)
    openinghours = models.CharField(max_length=9999)

Views.py

from django.http import HttpResponse
from django.shortcuts import render_to_response, render, get_object_or_404
from django.template import Context, loader
from hoursofDEV.models import GoogleData

def home(request):
    entries = GoogleData.objects.all()[:5]
    return render_to_response('index.html', {'entries': entries,})  

index.html

 {% if entries %}
<ul>
{% for GoogleData in entries %}
    <li><a href="/GoogleData/{{ GoogleData.name }}/">{{ GoogleData.name }}</a></li>
{% endfor %}
</ul>
{% else %}
    <p>Where's the Data?.</p>
{% endif %}

With the code that I've displayed, I constantly see my else "Where's the Data?.", I have hundreds of rows in GoogleData but I can't get any of them to show on the html page

Any guidance or pointing out of my newbie mistakes will be extremely helpful.

Thanks!

Upvotes: 1

Views: 2572

Answers (1)

mabdrabo
mabdrabo

Reputation: 1060

you didn't add the RequestContext, your return statement should look like >>

return render_to_response('index.html', {'entries': entries}, RequestContext(request))

and don't forget to import the RequestContext >> from django.template import RequestContext

Upvotes: 1

Related Questions