I have a problem with media files. I read everything on Net and tried all offered solutions but nothing works.
This is settings.py:
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,"static")
STATICFILES_DIRS = (os.path.join(BASE_DIR, './myapp/static/'), )
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
This is urls.py:
urlpatterns = [
path('application/admin/', admin.site.urls),
path('application/accounts/', include('django.contrib.auth.urls')),
path('application/', include('myapp.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
This is part of template where image needs to show:
{% if word.image %}
<img src="{{ word.image.url }}" alt="img" class="wordImg">
{% else %}
<p class="wordPar">No image to preview</p>
{% endif %}
Everything seems fine to me but obviously there is a mistake, because image cannot preview. I get this:
Thanks for help!