django - django 视图循环在 html 模板中不起作用
问题描述
我在 views.py 文件中创建了循环,然后通过 dictionary 。我已经在 django 项目的 html 文件中连接了该循环。它不工作。
视图.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>
解决方案
推荐阅读
- amazon-kinesis - 如何从 aws kinesis 流式传输实时数据以响应基于前端
- c - 在 C 中使用结构时的内存分配
- spring - 如果 kafka 关闭,弹簧执行器“健康”指标不会响应
- postgresql - 读取时带时区的 PostgreSQL 时间戳应用偏移量
- rx-swift - 处理时如何调用方法
- ios - 自定义字体可以在 Storyboard 中使用吗?
- android - 检测Android上安装的GameGuardian/防止GameGuard修改值
- java - Cucumber - Java8 - 使用 @Before 和 lambda 表达式
- css - 如何解决为什么 Bootstrap 4 的sticky-top 类在我的页面上不起作用?
- java - 如何调整 JVM 8 G1 参数以避免 Full GC(分配失败)