更新: 投稿を画像で更新しました。正確に何が欲しいかを今すぐ確認してください:
私のフロントページ:
ユーザー hase が「名前」という単語を入力しました。
ユーザーが検索を押した後、ユーザーはリストとチャートを取得していますが、「名前」という単語が検索バーに保持されていることがわかりますが、そこに表示したいです。
私の質問はわかりましたか?
私のviews.pyファイルコード:
#!/usr/bin/python
from django.core.context_processors import csrf
from django.template import loader, RequestContext, Context
from django.http import HttpResponse
from search.models import Keywords
from django.shortcuts import render_to_response as rr
import Cookie
def front_page(request):
if request.method == 'POST' :
from skey import find_root_tags, count, sorting_list
str1 = request.POST['word']
str1 = str1.encode('utf-8')
list = []
for i in range(count.__len__()):
count[i] = 0
path = '/home/pooja/Desktop/'
fo = open("/home/pooja/Desktop/xml.txt","r")
for i in range(count.__len__()):
file = fo.readline()
file = file.rstrip('\n')
find_root_tags(path+file,str1,i)
list.append((file,count[i]))
for name, count1 in list:
s = Keywords(file_name=name,frequency_count=count1)
s.save()
fo.close()
list1 = Keywords.objects.all().order_by('-frequency_count')
t = loader.get_template('search/front_page.html')
c = RequestContext(request, {'list1':list1,
})
c.update(csrf(request))
response = t.render(c)
response.set_cookie('word',request.POST['word'])
return HttpResponse(response)
else :
str1 = ''
template = loader.get_template('search/front_page.html')
c = RequestContext(request)
response = template.render(c)
return HttpResponse(response)
10個のxmlドキュメントでキーワードを検索し、各ファイルのキーワードの出現頻度を返すdjango検索を使用してアプリを作成しました。これは、xmlドキュメントのハイパーリンクリストとそれぞれのカウントとグラフとして表示されます。
サーバーでアプリを実行すると、ユーザーが検索バーに単語を入力すると、結果は同じページに完全に表示されますが、ユーザーが検索タブを押すと、単語は検索バーに保持されません。そのために、Cookieを使用しましたが、エラーが発生しています
'SafeUnicode' object has no attribute 'set_cookie'
なぜ?私はdjangoが初めてなので、助けてください