これは私のviews.pyファイルコードです(djangoの私のアプリ「検索」に存在します):
#!/usr/bin/python
from dango.http import HttpResponse
from skey import find_root_tags, count, sorting_list
from search.models Keywords
def front_page(request):
if request.method == 'POST' :
str1 = request.POST['word']
fo = open("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, count in list:
s = Keywords(file_name=name,frequency_count=count)
s.save()
fo.close()
return HttpResponseRedirect('/results/')
else :
str1 = ''
list = []
template = loader.get_tamplate('search/search.html')
response = template.render()
return HttpResponse(response)
def results(request):
list1 = Keywords.objects.all()
t = loader.get_template('search/results.html')
c = Context({'list1':list1,
})
return HttpResponse(t.render(c))
1)views.pyに「skey」ファイルをインポートしているので知りたかったので、この「skey.py」、「xml.txt」、および10個のxmlドキュメントも検索アプリディレクトリに保持する必要がありますか?
2)投稿後に「結果」ビューにリダイレクトしているので、urls.py、つまり「urlpatterns」でそれについて言及するにはどうすればよいですか。
3) それでは、「def front_page(request):」で「コンテキスト」について言及する必要がありますか?ビューのこの定義は、それがなくても正常に機能しますか?私によると、すべての定義でコンテキストを使用する必要がないためです。ビューの。
Django は私にとって初めてで、実際に使用した経験がありません。
助けてください。