我的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 %}
为什么会发生这种情况,我在哪里弄错了?而值存储在表中,我通过管理页面检查了它,那么为什么会显示?请帮忙。