0

私のviews.pyファイルコード:

#!/usr/bin/python 

from django.template import loader, RequestContext
from django.http import HttpResponse
#from skey import find_root_tags, count, sorting_list
from search.models import Keywords
from django.shortcuts import render_to_response as rr

def front_page(request):

    if request.method == 'POST' :
        from skey import find_root_tags, count, sorting_list
        str1 = request.POST['word'] 
        fo = open("/home/pooja/Desktop/xml.txt","r")

        for i in range(count.__len__()):

            file = fo.readline()
            file = file.rstrip('\n')
            find_root_tags(file,str1,i) 

            list.append((file,count[i]))

        sorting_list(list)

        for name, count1 in list:
            s = Keywords(file_name=name,frequency_count=count1)
            s.save()

            fo.close()

        list1 = Keywords.objects.all()
        t = loader.get_template('search/results.html')
        c = Context({'list1':list1,})

        return HttpResponse(t.render(c))

    else :  
        str1 = ''
        list = []
        template = loader.get_template('search/front_page.html')
        c = RequestContext(request)
        response = template.render(c)
        return HttpResponse(response) 

 <body BGCOLOR = #9ACD32">
<ul> 
{ % for l in list1 %}
        <li> {{l.file_name}}, {{l.frquency_count}}</li>
{ % endfor %}
</ul>

</body>

サーバーでアプリを実行すると、単語の入力を求められ、results.htmlにリダイレクトされ、次の出力が表示されます。

{ % for l in list1 %}

- List item,

{ % endfor %}

なぜこれが起こっているのか、どこを間違えているのですか?値がテーブルに格納されているのに対し、管理ページで確認したのに、なぜ表示されているのですか?助けてください。

4

2 に答える 2

1
{ % for l in list1 %}

する必要があります

{% for l in list1 %}

{ % endfor %}

する必要があります

{% endfor %}
于 2012-07-04T17:53:29.513 に答える
0

'{'と'%'の間にスペースを入れないでください

于 2012-07-04T17:54:17.097 に答える