Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法使用Django显示静态文件夹中的图像_Python_Html_Css_Django_Bootstrap 4 - Fatal编程技术网

Python 无法使用Django显示静态文件夹中的图像

Python 无法使用Django显示静态文件夹中的图像,python,html,css,django,bootstrap-4,Python,Html,Css,Django,Bootstrap 4,这是我的家。html 我无法在static/images/文件夹中显示图像。 虽然*[09/Mar/2020 15:52:09]“GET/static/images/mona.jpg HTTP/1.1”404 1669 *显示在终端中 {%block content%} {%load static%} 家 {%include“includes/header.html”%} 蒙娜丽莎 呐喊 {%include“includes/footer.html”%} {%endblock内容%} 在源

这是我的家。html 我无法在static/images/文件夹中显示图像。 虽然*[09/Mar/2020 15:52:09]“GET/static/images/mona.jpg HTTP/1.1”404 1669 *显示在终端中


{%block content%}
{%load static%}
家
{%include“includes/header.html”%}
蒙娜丽莎

呐喊

{%include“includes/footer.html”%} {%endblock内容%}
在源代码周围添加引号,如下所示

{% load static %}

<img src="{% static 'images/mona.jpeg' %}" alt="Avatar" style="width:100%;">
{%load static%}

生产环境中的静态文件由web服务器(apache、nginx)提供服务

在开发过程中,如果您使用的是django.contrib.staticfiles,并且DEBUG设置为True,则将自动提供app_name/static/app_name中的文件

如果文件是由用户在web应用程序中上载的,则需要编辑基本URL.py文件,如下所示

from django.conf.urls.static import static

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

For more info on this see  https://docs.djangoproject.com/en/3.0/howto/static-files/

对不起,伙计们,这是个打字错误。我真傻

在settings.py中

STATICFILES_DIRS = [
 os.path.join(BASE_DIR, 'the7thstreet/static'),
 '/var/www/static',
 ]
纠正

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

您可以共享从inspect元素创建的图像的url吗?它位于静态文件夹中,../static/images/mona.jpguse'mona.jpg'as mona.jpg不存在。我已经做了上述必要的更改,但仍然面临问题您可以发布您的settings.py文件和目录结构吗?
STATICFILES_DIRS = [
 os.path.join(BASE_DIR, 'static'),
 '/var/www/static',
 ]