[Python] Django MEDIA_URL and MEDIA_ROOT

Discussão em 'Python' iniciado por Stack, Junho 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to upload an image via the Django admin and then view that image either in a page on the frontend or just via a URL.

    Note this is all on my local machine.

    My settings are as follows:

    MEDIA_ROOT = '/home/dan/mysite/media/'

    MEDIA_URL = '/media/'


    I have set the upload_to parameter to 'images' and the file has been correctly uploaded to the directory:

    '/home/dan/mysite/media/images/myimage.png'


    However, when I try to access the image at the following URL:

    http://127.0.0.1:8000/media/images/myimage.png


    I get a 404 error.

    Do I need to setup specific URLconf patters for uploaded media?

    Any advice appreciated.

    Thanks.

    Continue reading...

Compartilhe esta Página