【问题标题】:Django Will Not Open Up Static File Image, Django 3Django 不会打开静态文件图像,Django 3
【发布时间】:2020-01-04 00:47:23
【问题描述】:

所以我一直在试图弄清楚为什么图像不会显示,并且我已经观看并阅读了很多东西,但我仍然找不到任何东西。这是我在这里的第一个问题。感谢您的帮助

HTML

{% load static %}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Nikhil's Portfolio</title>
</head>

<body>
test
<img scr="{% static 'static/homepage/wpap.jpg' %}" alt="why is it not working">
<img scr="{% static 'static/homepage/download.jpg' %}" alt="why is it not working">

</body>

</html>

我网站的 url.py(不是应用程序 url)

from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static


urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('homepage.urls'))
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

settings.py

STATIC_URL = '/static/'

STATICFILES_DIRS = [
    os.path.join(BASE_DIR, 'static'),
]

我的文件是如何排列的 img of file organization

【问题讨论】:

  • 我也在使用 django 3.0.1,而不是 3,如果有影响的话

标签: python html django


【解决方案1】:

试试这个

    {% static 'homepage/wpap.jpg' %}

代替

    {% static 'static/homepage/wpap.jpg' %}

【讨论】:

  • 不,还是一样。感谢您的帮助。
【解决方案2】:

这需要改变:

<img scr="{% static 'static/homepage/wpap.jpg' %}" alt="why is it not working">

到这里:

<img src="{% static 'static/homepage/wpap.jpg' %}" alt="why is it not working">

“scr”会变成“src”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-25
    • 2012-02-29
    • 2012-04-30
    • 2015-03-10
    • 1970-01-01
    • 2017-03-05
    相关资源
    最近更新 更多