Python Django项目中显示为断开图像的图像

Python Django项目中显示为断开图像的图像,python,django,django-templates,Python,Django,Django Templates,我在django项目中得到了一个损坏的图像,但据我检查,代码看起来是正确的。 下面是settings.py中的代码: STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static'), ) STATICFILES_FINDERS = [ 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.s

我在django项目中得到了一个损坏的图像,但据我检查,代码看起来是正确的。 下面是settings.py中的代码:

STATIC_URL = '/static/'

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

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

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
我还导入了“模板”部分中的“媒体”选项:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
            ],
        },
    },
]
下面是我在模板中使用的代码

{% if request.user.profile.picture %}
<img src="{{ request.user.profile.picture.url }}" height="35" class="d-inline-block align-top rounded-circle">
{% else %}
<img src="{% static 'img/default-profile.png' %}" height="35" class="d-inline-block align-top rounded-circle">
{% endif %}
{%if request.user.profile.picture%}
{%else%}
{%endif%}
default-profile.png图像加载正确,但其他配置文件图片加载不正确,尽管它们已正确加载到媒体文件夹,并且其URL在数据库中显示正确。有人知道我做错了什么吗

编辑:

图像的HTML输出如下所示:

<img src="/media/users/pictures/Foto.jpg" height="35" class="d-inline-block align-top rounded-circle">


检查src标记时,它看起来是正确的,因为它将媒体URL与存储在其后数据库中的值相匹配。

出现的情况是,您在开发过程中没有正确地提供媒体文件。您可以尝试将其附加到站点的url.py文件的
urlpatterns
列表中

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

有关更多详细信息,请参阅。

如果您尝试使用完整路径/媒体访问浏览器中的图像资源…….jpg发生了什么?@t.stv Error 404。因此,您的图像不在服务器上。您可以访问媒体文件夹中的任何内容吗?