如何检查x
变量是否为 == "about" 字符串?
我尝试:
{% for x in p %}
{% if x == "about" %}
<a href="/about/">About</a>
{% endif %}
{% endfor %}
{{ x }}
= 关于
但不起作用(if
不显示的内容)
编辑:
def search(request):
if 'search' in request.GET:
term = request.GET['search']
if len(term) > 3:
p = Chunk.objects.filter(Q(content__contains=term) | Q(
key__contains=term))
count = p.count()
return render_to_response('search_result.html',
{'p': p, 'count': count},
context_instance=RequestContext(request))
....
Chunk
来自 django-chunks 应用程序
p
我key
从这个:
class Chunk(models.Model):
key = models.CharField(_(u'Key'), help_text=_(u"A unique name for this chunk of content"), blank=False, max_length=255, unique=True)
content = models.TextField(_(u'Content'), blank=True)
description = models.CharField(_(u'Description'), blank=True, max_length=64, help_text=_(u"Short Description"))