2012-10-14 104 views
0

我的視圖渲染不正確。兩個視圖的格式都相同(index.htmlmq.html),並且index.html工作正常 - 它會爲每個子彈創建一個帶有1個值的項目符號列表。Django視圖不能在HTML中呈現

但是,mq.html會創建正確數量的項目符號,但是單詞不顯示在頁面上。任何人都可以告訴我代碼有什麼問題嗎? ModelsViewsHTML

型號:

class Movie(models.Model): 
    title = models.CharField(max_length = 500) 
    pub_date = models.DateTimeField('date published') 
    def __unicode__(self): 
     return self.title 
    def was_published_recently(self): 
     return self.pub_date >= timezone.now() - datetime.timedelta(days=1) 

class Question(models.Model): 
    movie = models.ForeignKey(Movie) 
    question_text = models.CharField(max_length = 1000) 
    def __unicode__(self): 
     return self.question_text 

瀏覽:

def index(request): 
    r = Movie.objects.all().order_by('-pub_date') 
    return render_to_response('mrt2/index.html', {'latest_movie_list': r}) 

def movie_questions(request, movie_id): 
    p = Movie.objects.get(pk=movie_id) 
    k = Question.objects.filter(movie=p) 
    return render_to_response('mrt2/mq.html', {'movie':p, 'the_question':k}) 

HTML:

的index.html

<h1> Test </h1> 

{% if latest_movie_list %} 
    <ul> 
    {% for movie in latest_movie_list %} 
     <li><a href="/movie/{{ movie.id }}/">{{ movie.title }}</a></li> 
    {% endfor %} 
    </ul> 
{% else %} 
    <p>No movies are available.</p> 
{% endif %} 

mq.html

{{ movie.title }} 

{% if the_question %} 
    <ul> 
    {% for each in the_question %} 
     <li><a href="/movie/{{ movie.id }}/{{ question.id }}/">{{ question.question_text }}</a> </li> 
    {% endfor %} 
    </ul> 
{% else %} 
    <p>No questions have been asked.</p> 
{% endif %} 

回答

1

for each迴路不指定任何一個question

此:

{% for each in the_question %} 

需要是:

{% for question in the_question %} 
+0

實際上 {%爲the_question%每一個問題} 沒有工作,但在拿出每個 {%的問題the_question%} 工作。謝謝! –

+0

啊,它是分配給'each'。 –