Django static img没有显示在我的博客中

时间:2014-04-23 18:46:25

标签: python django image templates static

首先让我说我是一名学生想学习django ...... 我通过一个教程完成了我的应用程序,我的模板中显示的图像有问题,它只是显示框架中的图像...这是我的HTML代码:

            <aside>
                <h4>Historico</h4>
                {% for month in months %}
                <p><a href="{url 'blog.views.month' month.0 month.1}">{{ month.2 }}</a></p>

                {% endfor %}
                <h4>Sobre mi</h4>
                <img class="pic" src="{{ STATIC_URL }}/static/img/foto.jpg"  alt="foto"/>

                <img class="picbig" src="{{ STATIC_URL }}/static/img/foto.jpg"  alt="foto grande"/>
                <p>Soy un doge san OP platino IV lan pls</p>
            </aside>

我的图片“foto.jpg”没有显示,这是我的settings.py for static

STATIC_URL = '/static/'
STATICFILES_DIRS = (
"C:/Users/Abdul Hamid/PycharmProjects/misitioweb/static",
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',

)

我的img就在这样的文件夹中

`C:\Users\User-Name\PycharmProjects\misitioweb\`

`blog-
-templtates
--frontpage.html
--otherthing.html
-__init__.py
-admin.py
-models.py
-test.py
-views.py
mysite-
-__init__.py
-settings.py
-urls.py
-wsgi.py
manage.py
-etc..
static-
--img
---foto.jpg
`

我一直在尝试更改img标记中的代码以获取不同的结果,例如将静态文件夹加载到模板中,如下所示: {{from static import staticfiles}}

我做错了什么,我已经尝试寻找更多信息,但没有任何工作......请帮助我! 无论如何 谢谢你的时间

2 个答案:

答案 0 :(得分:1)

您的src属性看起来不正确。

<img class="pic" src="{{ STATIC_URL }}/static/img/foto.jpg"  alt="foto"/>

应该是

<img class="pic" src="{{ STATIC_URL }}img/foto.jpg"  alt="foto"/>

由于STATIC_URL已经在处理你的网址添加/ static /。如果您在浏览器中使用调试器工具并查看该图像的src,您可能会看到它说&#34; /static/static/img/foto.jpg"什么时候应该是&#34; /static/img/foto.jpg"

答案 1 :(得分:0)

还要确保通过运行以下方式收集静态图像文件:

python manange.py collectstatic
相关问题