0

I have created loop in views.py file then through dictionary . I have connected that loop in html file in django project. And it is not working.

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})

Error occuring in 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>
Ivan Starostin
  • 7,445
  • 5
  • 17
  • 32
  • Likely dupe of https://stackoverflow.com/questions/8018973/how-to-iterate-through-dictionary-in-a-dictionary-in-django-template – Peter DeGlopper Jun 06 '19 at 15:36
  • Possible duplicate of [What are valid values for the id attribute in HTML?](https://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html) – Yushin Jun 06 '19 at 15:36
  • Possible duplicate of [how to iterate through dictionary in a dictionary in django template?](https://stackoverflow.com/questions/8018973/how-to-iterate-through-dictionary-in-a-dictionary-in-django-template) – MasterAler Jun 06 '19 at 16:37

0 Answers0