使用django在服务器上没有输出

时间:2012-07-04 17:21:30

标签: python django linux ubuntu-10.04

我的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 %}

为什么会发生这种情况,我在哪里错了?而值存储在表格中,我通过管理页面查看,然后为什么要显示? 请帮忙。

2 个答案:

答案 0 :(得分:1)

{ % for l in list1 %}

应该是

{% for l in list1 %}

{ % endfor %}

应该是

{% endfor %}

答案 1 :(得分:0)

永远不要在'{'和'%'

之间加一个空格