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
Select all Open in new window
admin.py
from django.contrib import admin
from .models import Pin
admin.site.register(Pin)
Select all 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),
]
Select all 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})
Select all 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>
Select all 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>
Select all Open in new window
Why isn't my data coming up? What am I missing?