KSHMR
KSHMR

Reputation: 809

Django blank page

This is my index.html file:

{% extends "base_site.html" %}
{% block content %}

{% if info %}
    <ul>
    {% for object in info %}
        {{ Hello }}
    {% endfor %}
    </ul>
{% else %}
    <p>No objects are available.</p>
{% endif %}
{% endblock %}

This is my views.py

from django.shortcuts import render
from django.http import HttpResponse
from django.template import RequestContext, loader
from notendur.models import *
from django.views import generic

class IndexView(generic.ListView):
    template_name = 'notendur/index.html'
    context_object_name = "info"

    def get_queryset(self):
        """Return the last five published polls."""
        return Information.objects.all()

This is my models.py:

from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class Information(models.Model):
    title = models.CharField(max_length = 200)
    body = models.TextField()
    date = models.DateTimeField()

    def __unicode__(self):
        return self.title

class InformationChild(models.Model):
    information = models.ForeignKey(Information)
    child_text = models.CharField(max_length = 200)

    def __unicode__(self):
        return self.child_text

When I start the server, however, nothing appears. This has to be some url-link issue, because the else clause doesn't even activate. Perhaps you want urls.py as well?

Let me know if you need further information.

Upvotes: 0

Views: 353

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599450

The error is not in the use of info, it's in what's inside the for loop: {{ Hello }} is not an item in the context. Use {{ object.title }}, for example.

Upvotes: 3

Related Questions