I`ve created a new Django project and ran into a problem with static images. So, apparently when i was connecting my css and javascript files with static it worked well, but when i tried to connect images they won't load. here is my settings.py
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_DIRS = ['static']
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
urls.py
from django.contrib import admin
from django.urls import path, include
from store import settings
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('mstore.urls')),
]
if settings.DEBUG:
from django.conf.urls.static import static
urlpatterns += static(settings.MEDIA_URL,
document_root=settings.MEDIA_ROOT)
here is example of how i display it in template
<a href="#" class="item__image">
<picture><source srcset="img/collections/featured/02.webp" type="image/webp">
<img src="{% static 'mstore/img/collections/featured/02.png' %}" alt="Lore Walnut"></picture></a>
Please, before answering note that i checked the src of the image in browser, and it worked.
i copied this link and pasted in browser and got this
Besides, css and js works great, so i think the problem is in images
I tried to run python manage.py collectstatic and it worked perfectly.
So I just forgot to static my srcsets and it caused the problem.