这是我index.html
文件:Django的空白页
{% 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
?
让我知道你是否需要更多信息。
用废话替换信息似乎会激活else子句。那么这肯定与信息不被发现有关。事实上这是不正确的。应该在那里而不是信息?我想获取信息对象。 – KSHMR
将'get_queryset'中的'.all()'改为'.none()',看看是否{%else%}'被触发。 –