Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何显示图像的其他图像是无的_Python_Django - Fatal编程技术网

Python 如何显示图像的其他图像是无的

Python 如何显示图像的其他图像是无的,python,django,Python,Django,在我认真思考之后,我只是不知道我的代码出了什么问题以及如何修改它 问题在于:当用户插入url时,如果该url是指向youtube的链接,则需要显示youtube缩略图。如果该url不是youtube视频的链接,则需要显示post.image(默认图像)。但是post.image无法显示 如果我选择to表示if/else语句错误,则可以显示这两个图像 这是我的全部代码; 我将通过下面的代码进行评论,如果有人能告诉我我做错了什么,我将非常感激 视频标签来自此第三方应用程序django嵌入式视频。

在我认真思考之后,我只是不知道我的代码出了什么问题以及如何修改它

问题在于:当用户插入url时,如果该url是指向youtube的链接,则需要显示youtube缩略图。如果该url不是youtube视频的链接,则需要显示post.image(默认图像)。但是post.image无法显示

如果我选择to表示if/else语句错误,则可以显示这两个图像

这是我的全部代码; 我将通过下面的代码进行评论,如果有人能告诉我我做错了什么,我将非常感激 视频标签来自此第三方应用程序django嵌入式视频。


{%if post.main_image%}//if post有main_image
//显示该图像
{%elif post.url%}//如果post有url
{%video post.url作为我的视频%}//将post.url设置为我的视频(我想问题从这里开始)
{%if my_video%}//如果我的_video在那里
//显示视频缩略图
{%else%}//如果我的视频不在那里,并且post.url不是youtube的链接
//显示post.image
{%endif%}
{%endvideo%}
{%else%}
{%endif%}
我做错了什么

编辑:我想找到了一个问题,但不确定如何解决 当我这样做的时候
{%video post.url作为my_video%}我正在将post.url设置为my_video,当我这样做时,无论url是否为youtube链接,它都会说是的,它存在…现在退一步…

您是否尝试过去掉{%video块,只输入“hello world”要查看是条件导致了问题还是视频模板标记?@Phoebebe我发现了问题….请查看编辑如何在{%video节之外对url作为youtube进行测试,即{%if“youtube”in post.url%}
<td>
  {% if post.main_image %} //if post has main_image
    <img src="{{post.get_image_url}}"  class="img-rounded" alt="☺" height="75" width="75"/>//display that image
  {% elif post.url %}//if post has url
    {% video post.url as my_video %} //setting post.url as my_video(problem starts here I think)
      {% if my_video %} //if my_video is there
        <img src="{{ my_video.thumbnail }}" class="img-rounded" alt="☺" height="75" width="75"/> //display the video thumbnail
      {% else %} //if my_video isn't there and post.url isn't a link to youtube
        <img src="{{post.image}}"  class="img-rounded" alt="☺ " height="75" width="75"/> //display post.image
      {% endif %}
    {% endvideo %}
  {% else %} 
    <img src="{{post.thumbnail}}"  class="img-rounded" alt="☺" height="75" width="75"/>
  {% endif %}
</td>