我正在尝试添加一个在django模板的个人资料图像的评论后。。。如果模型中没有配置文件图像,那么我想用样式化的文本代替图像。但我担心的是如何告诉django模板,如果图像存在或不存在。。。你知道吗
<div class="comment-author">
{% for image in profile %}
{% if image.profile|slugify == comment.author %}
{% with "exist" as img %} <!-- if image exist create img variable -->
<img src="{{ image.profileImg.url }}" alt="{{ image.profile }}">
{% endif %}
{% endfor %}
{% if not img %} <!-- using img variable for checking -->
<span class="userImg"><b>{{ comment.author|make_list|slice:':2'|join:'' }}</b></span>
{% endif %}
{% endwith %} <!-- closing the with statement -->
在上面的代码中,我尝试使用“with”创建一个变量img,但在模板中出现错误。。。我该怎么处理这个?你知道吗
模板标记未正确关闭。另请参考docs,对代码进行了一点改进。你知道吗
相关问题 更多 >
编程相关推荐