简体   繁体   English

Django在模板中移动变量<img src=“”>

[英]Django move variable in template for <img src=“”>

I have a variable contain url my file image我有一个包含 url 我的文件图像的变量

m='media/abc2021x07x13/ch00002_01000000025099767142400187070_29H75756.jpg'
return render(request, 'new_template/view_image.html',{'form1': m})

and move to template to display并移至模板以显示

{% load static %}
<img src="{% static '{{form1}}' %}"
 width="1440" height="948" /

it can't display but when i try this, it can display它无法显示,但是当我尝试此操作时,它可以显示

{% load static %}
<img src="{% static 'media/abc2021x07x13/ch00002_01000000025099767142400187070_29H75756.jpg' %}"
 width="1440" height="948" />

你不需要引号和键:

<img src="{% static form1 %}" width="1440" height="948" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM