media file not serve in django with wihtenoise

126 views Asked by At

Media files in Django are not visible and are not displayed. I used WhiteNews. like this:

in wsgi.py i add this:

    application = WhiteNoise(application, root=BASE_DIR / 'static')
    application.add_files(BASE_DIR / 'media', prefix='mdeia/')

in settings.py i add this:

    INSTALLED_APPS = [
      'whitenoise.runserver_nostatic',
        .
        .
        .

    MIDDLEWARE = [
      'django.middleware.security.SecurityMiddleware',
      'whitenoise.middleware.WhiteNoiseMiddleware',
       .
       .
       .

    STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'

    STATIC_ROOT= BASE_DIR / 'static'
    STATIC_URL = '/static/'

    MEDIA_URL = '/media/'
    MEDIA_ROOT= BASE_DIR / 'media/'

in html file :

    <img src="{{user.photo.url}}" style=" width:90px; height:90px; border-radius:50px 50px 50px 50px;">

   

and in models.py i using this:

     photo=models.ImageField(upload_to='users/photos/',default='user-photo.png',null=True,blank=True)

I download static files without any problems and media files are saved without any problems but they are not downloaded. Thank you for your help.

0

There are 0 answers