Django空白页

时间:2014-06-06 12:17:15

标签: python django

这是我的index.html文件:

{% 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 %}

这是我的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()

这是我的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

但是,当我启动服务器时,没有任何内容出现。这必须是一些url-link问题,因为else子句甚至不会激活。也许你也想要urls.py

如果您需要更多信息,请与我们联系。

1 个答案:

答案 0 :(得分:3)

错误不在info的使用中,它在for循环内部:{{ Hello }}不是上下文中的项。例如,使用{{ object.title }}

相关问题