Django can't acces media files, 404 Page not found

I recently started to learn Django but I'm still struggeling with accessing media files. My settings.py file includes the following:

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

My urls.py in the project directory contains the following.

urlpatterns = [
    path('admin/', admin.site.urls),
    path('', include('store.urls'))
]

if st.DEBUG:
    urlpatterns += django_Static(st.MEDIA_URL, document_root=st.MEDIA_ROOT)

When I then try to load an image via a GET request I get the following message: "

Page not found (404)
...
Using the URLconf defined in ecommerce_project.urls, Django tried these URL patterns, in this order:

admin/
[name='store_homepage']
^media/(?P<path>.*)$

The current path, media/product_pictures/256132756_922283745365869_1303861998719790800_n.jpg, matched the last one.

I really don't know what to do since I tried everything. Has someone also stumbled accross this problem?

I just had to change the position of MEDIA_URL and MEDIA_ROOT

    MEDIA_URL = '/media/
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Back to Top