Python 使用collectstatic复制到静态\u根目录,但图像不可见

Python 使用collectstatic复制到静态\u根目录,但图像不可见,python,django,collectstatic,Python,Django,Collectstatic,需要按照中的建议从公共目录访问静态文件 命令,python manage.py collectstatic 复制到STATIC_ROOT,但在html中引用它时,会抛出错误 Not Found: /static/teststatic/images/product-5.jpg 如何使它与来自静态根位置的文件一起工作 我已经试过了,并且成功了 <img src="{% static 'teststatic/static/teststatic/images/product-5.jp

需要按照中的建议从公共目录访问静态文件

命令,
python manage.py collectstatic

复制到STATIC_ROOT,但在html中引用它时,会抛出错误

Not Found: /static/teststatic/images/product-5.jpg
如何使它与来自静态根位置的文件一起工作

我已经试过了,并且成功了

<img src="{% static 'teststatic/static/teststatic/images/product-5.jpg' %}" alt="Trulli" width="500" height="333">
视图.py

from django.urls import path
from . import views

app_name = 'teststatic'

urlpatterns = [
    path('tstatic/', views.tstatic, name='tstatic'),
]
from django.shortcuts import render

# Create your views here.


def tstatic(request):
    return render(request, 'tstatic.html', {})
DEBUG = True
.
.
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'


STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

STATICFILES_DIRS = (
    ('testcss', os.path.join(BASE_DIR, 'testcss', 'static', 'testcss')),
    ('helpdesk', os.path.join(BASE_DIR, 'helpdesk', 'static', 'helpdesk')),
    ('teststatic', os.path.join(BASE_DIR, 'teststatic', 'static', 'teststatic')),
    (os.path.join(BASE_DIR, 'staticfiles'))
)

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
设置.py

from django.urls import path
from . import views

app_name = 'teststatic'

urlpatterns = [
    path('tstatic/', views.tstatic, name='tstatic'),
]
from django.shortcuts import render

# Create your views here.


def tstatic(request):
    return render(request, 'tstatic.html', {})
DEBUG = True
.
.
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'


STATICFILES_FINDERS = [
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]

STATICFILES_DIRS = (
    ('testcss', os.path.join(BASE_DIR, 'testcss', 'static', 'testcss')),
    ('helpdesk', os.path.join(BASE_DIR, 'helpdesk', 'static', 'helpdesk')),
    ('teststatic', os.path.join(BASE_DIR, 'teststatic', 'static', 'teststatic')),
    (os.path.join(BASE_DIR, 'staticfiles'))
)

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
tstatic.html

{% load staticfiles %}
<!DOCTYPE html>
<html>
<body>

<h2>HTML Image</h2>
<img src="{% static 'teststatic/images/product-5.jpg' %}" alt="Trulli" width="500" height="333">

</body>
</html>

请在
设置.py
中显示调试状态,false还是true?如果为False,则可能需要在settings.py中查看此帖子,debug=True,