In Django, my data isn't rendering

Shana H
Shana H used Ask the Experts™
on
I'm learning Django, and trying to see if I can come up with a simple app, that just keep track of text only pins.

I can access the admin and view and create objects there without problem. What I am having trouble with is understanding why the data isn't coming up in the template.

My code is below.

models.py
from django.db import models
from django.utils import timezone


class Pin(models.Model):
    created_at = models.DateTimeField(default=timezone.now)
    title = models.CharField(max_length=255, default="Untitled")
    description = models.TextField(default="")

    def __str__(self):
        return self.title

Open in new window


admin.py
from django.contrib import admin
from .models import Pin

admin.site.register(Pin)

Open in new window


urls.py
from django.conf.urls import url
from django.contrib import admin
from . import views

urlpatterns = [
    url(r'^admin/', admin.site.urls),
    url(r'^$', views.pin_list),
]

Open in new window


view.py
from django.shortcuts import render
from . models import Pin


def pin_list(request):

    pins = Pin.objects.all()
    return render(request, "pin_list.html", {'pins': pins})

Open in new window


pin_list.html
{% load staticfiles %}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Pins</title>
</head>
<body>


<img height = "50px" src = "{%  static "images/logo.jpg" %}" >

<ul>
{% for p in pins %}

    <li>{{ p.tile }}</li>

{% endfor %}
</ul>

</body>
</html>

Open in new window


When I runserver and look at the "view source" of the resulting html I get this
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Pins</title>
</head>
<body>


<img height = "50px" src = "/static/images/logo.jpg" >

<ul>

</ul>

</body>
</html>

Open in new window


Why isn't my data coming up? What am I missing?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Sr Software Engineer
Commented:
looks like you have a typo.  should be p.title, not p.tile.  That can cause this.
Cyclops3590Sr Software Engineer

Commented:
this was tested in my own lab so unless it was a typo in pasting to EE that was the issue

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial