0

My Django files are loading after upload and are shown in the media folder, however I cannot access them at localhost:<PORT>/media/<FILENAME._EXT>. I've looked at several other answers on stackoverflow and they haven't worked. For example adding the urlpatterns += static(...), having DEBUG=True in settings.py.

When accessing: http://localhost:8000/media/controller.gif:

Error:

lightchan-backend-1   | Not Found: /media/controller.gif
lightchan-backend-1   | 2022-03-06 16:37:34,875 WARNING  Not Found: /media/controller.gif

In settings.py:

DEBUG = True
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media/')

In my urls.py:

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

from . import views

urlpatterns = [
  path('', views.index, name='index'),
  path('comment/<int:comment_id>/', views.comment, name='comment'),
  path('comments/', views.comments, name='comments'),
  path('reply/<int:incoming_id>/', views.reply, name='reply')
]

# if settings.DEBUG is True:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Ivan Starostin
  • 8,798
  • 5
  • 21
  • 39
yosemeti
  • 206
  • 4
  • 15

0 Answers0