从静态文件夹将图像添加到Django模板-Django [英] Adding an image into a django template from the static folder - Django
本文介绍了从静态文件夹将图像添加到Django模板-Django的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Django模板,我想从应用程序中的静态文件夹中向该文件添加静态图像。
我正在尝试,但是模板上没有任何内容。
I have a Django template and I want to add a static image to the file from my static folder that I have within the application. I am trying to but nothing is appearing on the template.
有人知道我的错误来自哪里吗?
这是我的代码:
{% extends "base.html" %}
{% block content %}
<div class="row">
<div class="col">
<img src="static/images/Artboard1.png" alt="">
<h2>{{ currentUser.username }}</h2>
</div>
<a href="{% url 'logout' %}">Logout</a>
{% endblock %}
这是我的目录的图像:
推荐答案
在扩展
{% extends "base.html" %}
{% load staticfiles %}
然后在 img HTML标签
<img src="{% static 'images/Artboard1.png'%}" alt="">
这篇关于从静态文件夹将图像添加到Django模板-Django的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文