【问题标题】:Display images in visual studio with Django and html [django]使用 Django 和 html 在 Visual Studio 中显示图像 [django]
【发布时间】:2021-08-23 00:29:39
【问题描述】:

我正在尝试使用 D jango 在我的 html 页面上显示图片,但它没有显示

它是这样显示的

我在设置中添加了这段代码

    STATIC_URL = '/static/'
STATIC_ROOT = posixpath.join(*(BASE_DIR.split(os.path.sep) + ['static']))


MEDIA_URL='/media/'
MEDIA_ROOT=os.path.join(BASE_DIR, 'media')

这个在网址的末尾

] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

我有html页面,我写了这样的图像代码

<img src="images/offer.jpg" alt="" />

这是我的文件

希望我能在这里找到解决方案

【问题讨论】:

    标签: django visual-studio visual-studio-code django-templates visual-studio-2019


    【解决方案1】:

    我解决了

    我把代码改成了

    {% load staticfiles %}
    <img src="{% static "app/images/offer.jpg" %}" alt="My image"/>
    

    啊终于感谢上帝了 :D 希望这可以帮助任何有同样问题的人

    【讨论】:

      猜你喜欢
      • 2015-04-15
      • 1970-01-01
      • 2020-03-19
      • 2019-02-21
      • 2023-04-01
      • 1970-01-01
      • 2015-06-04
      • 2017-05-31
      • 1970-01-01
      相关资源
      最近更新 更多