我按照了教程中指示的步骤进行操作,但是仍然看不到该图像。它找到了它,但没有显示它:“ GET /static/imagenes/triste.png HTTP / 1.1” 4041782。图像位于static / imagenes中。
{% load static %}
<img src= "{% static 'imagenes/feliz.png' %}" alt="hola" >
settings.py
STATIC_URL = '/static/'
STATICFILES_DIR = [os.path.join(BASE_DIR, 'static')]
STATIC_ROOT = os.path.join(BASE_DIR,"static")
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
urls.py
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('configuracionSecreta/', include('apps.configuracion.urls')),
path('dialogo/', include('apps.dialogo.urls')),
path('posicionamiento/', include('apps.dialogo_pos.urls')),
path('resultados/', include('apps.resultados_test.urls')),
path('', include('apps.test_datos.urls')),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
├───.vscode
├───apps
│ ├───configuracion
│ ├───dialogo
│ ├───dialogo_pos
│ ├───resultados_test
│ └───test_datos
├───media
├───static
│ ├───bower_components
│ ├───imagenes
├───templates
│ ├───base
│ ├───configuracion
│ ├───dialogo
│ ├───dialogo_pos
│ ├───resultados_test
│ └───test_datos
└───tfg_project
#dialogo_pos/urls.py
from django.urls import path
from apps.dialogo_pos.views import *
from django.conf.urls.static import static
from django.conf import settings
urlpatterns = [
path('', dialogoPosIni.as_view(), name='inicio'),
path('final', dialogoPosFin.as_view(), name='fin')
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)