django 模板标签if
我在模板中写了ifelse但是显示是有问题的views:user={"name":'tom',"age":23,"sex":'man'}book_list=['pytho...
我在模板中写了if else 但是显示是有问题的
views:
user = {"name":'tom',"age":23,"sex":'man'}
book_list = ['python','php','java','ruby']
return render(req,"index.html",{"h1":"Hello","book_list":book_list,"user":user})
index.html:
{% if user %}
<li>user: {{user.name}}</li>
<li>age: {{user.age}}</li>
<li>sex: {{user.sex}}</li>
{% else %}
无用户
{% endif %}
我把render后面的user删除后,页面不会出先else的内容,而是li里后面是空的.
新手求帮助呢. 展开
views:
user = {"name":'tom',"age":23,"sex":'man'}
book_list = ['python','php','java','ruby']
return render(req,"index.html",{"h1":"Hello","book_list":book_list,"user":user})
index.html:
{% if user %}
<li>user: {{user.name}}</li>
<li>age: {{user.age}}</li>
<li>sex: {{user.sex}}</li>
{% else %}
无用户
{% endif %}
我把render后面的user删除后,页面不会出先else的内容,而是li里后面是空的.
新手求帮助呢. 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询