我已经在views.py文件中创建了循环,然后通过dictionary创建了循环。我已经在Django项目的html文件中连接了该循环。而且它不起作用。
views.py
def count(request):
data= request.GET['fulltextarea']
text=data.split()
counted_text=len(text)
worddictionary={}
for word in text:
if word in worddictionary:
worddictionary[word] += 1
else:
worddictionary[word] = 1
return render(request,'count.html',{'fulltextarea':data, 'len':counted_text,'worddictionary': worddictionary})
html中出现错误
<body> <h1>Counted</h1>
<h2> Your text</h2>
{{fulltextarea}} <br>
<h2>Words count</h2>
Total word = {{len}} <br>
<h2>Number of each word</h2>
{% for word, value in worddictionary %}
{{ word }} = {{ value }}
{% endfor %}
</body>