Python + Django space delimited data and passed to the front page

# urls.py
url('show/', views.show),

Adding the name of the database table as a "test", which has physical field name is "keyword", which stores similar to the "banana orange apple" of data, which uses space "" to separate between each word, we need at the front press the space separate display data.

# views.py
import re

def show(request,param):
    post = models.Test.objects.all()
    kw = post.keyword
    res = re.split(" ", kw)
    return render(request,"show.html",{"res": res})

Is displayed in the front

<!-- show.html -->
关键字: {% for t in res %}
<a>{{ t }}</a> {% endfor %}

 

Guess you like

Origin www.cnblogs.com/hjy415/p/10941834.html