无法加载我的django模板中的图像 [英] Can't load image in my django template

查看:234
本文介绍了无法加载我的django模板中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目文件夹是:

mrdoorbeen
manage.py
    mr_doorbeen
         setting.py
    mrdoorbeen
      migrations
      templates
         index.html
         profile
             profile.html

我想在我的 profile.html 文件中加入图片。
i在 profile.html 的顶部使用 {%load staticfiles%} ,并在图像上使用此代码来源:

I want to include a image in my profile.html file. i use {% load staticfiles %} in top of the profile.htmland use this code at image source :

<img src="{% static "image/example.jpg" %}" alt="cant'load"/>

我在一个 mr_doorbeen 并将其称为 static ,并在静态文件夹中创建一个图像文件夹和图像,我把一个示例.jpg 但它不工作。 我的 static 文件夹路径错误或什么?
我应该在哪里放置我的静态文件夹

and i make a folder in a mr_doorbeen and call it static and in static folder make a image folder and image i put a example.jpg but it doesn't work . my static folder path is wrong or what? where should i put my static folder in this project

推荐答案

对于给定的目录结构,您可以将静态文件放在与文件目录相同的级别上, mr_doorbeen / settings.py

For the given directory structure, You can put your static files on same level as of the directory with file, mr_doorbeen/settings.py

mrdoorbeen
manage.py
    mr_doorbeen
      setting.py
    mrdoorbeen
      migrations
      templates
         index.html
         profile
             profile.html
    static/

你可以将静态文件设置为所述位置,如下所示。

You can set the static files to the said location as follows.

# Static files configurations.
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

这篇关于无法加载我的django模板中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆