# urls.py url('show/', views.show),
加入数据库里表的名称为“test”,其中有体格字段名称为“keyword”,其中存储着类似“香蕉 橘子 苹果”的数据,即每个词之间用空格“ ”隔开,我们在前端需要按空格分开显示数据。
# views.py import re def show(request): post = models.Test.objects.all() kw = post.keyword res = re.split(" ", kw) return render(request,"show.html",{"res": res})
在前端显示
<!-- show.html -->
关键字: {% for t in res %} <a>{{ t }}</a> {% endfor %}