這是我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%}'被觸發。 –