Forums

My static images show up but not my dynamic images

Hi I uploaded my site through pythonanywhere everything works fine except the images: My static images show up however when I try to upload some images using a button nothing happens, it displays an icon image but not the image I put.

My logs are this:

2023-01-30 18:31:52,240: Not Found: /login/assets/libs/jquery/jquery.min.js
2023-01-30 18:31:52,316: Not Found: /login/assets/libs/node-waves/waves.min.js
2023-01-30 18:38:05,453: Not Found: /media/uploads/my_profile/1674481351499.jpg
2023-01-30 18:38:05,454: Not Found: /media/uploads/picture_X1B3iwI.jpg
2023-01-30 18:38:08,508: Not Found: /media/uploads/picture_X1B3iwI.jpg

I review and I have this route when I type "ls" in my console: /media/uploads, and I realize that all the images I uploaded are here.

My media settings are this:

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

in urls.py I have this:

urlpatterns = [
    path('i18n/', include("django.conf.urls.i18n")),
    path('carros/',include('carros.urls')),
#search
    path('search/',sistema_views.search, name='search'),
    path('', include('dashboard.urls'))
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

if settings.DEBUG:
    urlpatterns += (
        static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +
        static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
        )

In WEB section I type this:

/media/     /home/mysite/ws2022/media/uploads

Do you have any idea about what happens? Thanks!!

Make sure that you are serving the media files, too. See https://help.pythonanywhere.com/pages/StaticFiles/ and https://help.pythonanywhere.com/pages/DebuggingStaticFiles/

does this work even with media files? I saw that those links are for staticfiles

Media files are normally served the same way static files are. See also https://help.pythonanywhere.com/pages/DjangoStaticFiles

nice tutorial, thanks :) I could fix it

Glad to hear that you made it work!