1

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?

3
  • Show your folder structure Commented Sep 5, 2022 at 18:29
  • is it running in a container? Commented Sep 5, 2022 at 19:28
  • You have an unterminated string. MEDIA_URL = '/media/ is not being closed out. Commented Sep 5, 2022 at 19:58

1 Answer 1

0

I just had to change the position of MEDIA_URL and MEDIA_ROOT

    MEDIA_URL = '/media/
    MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.