Django /media/ files not served in production on hosting

I really feel like i am stuck, and hosting support doesn't include configuration help so maybe someone here would know

i have django server with model:

class Video(models.Model):
    thumbnail = models.ImageField(upload_to='thumbnails/', blank=True, null=True) 

saved here in folder thumbnails: MEDIA_URL = '/media/' MEDIA_ROOT = '/home/username/domains/domain.com/djangoapp/media'

when i later want to use uploaded image in html:

<img src="{{ video.thumbnail.url }}" alt="{{ video.title }}" class="video-thumbnail">

it it not served in production (works on debug=True), file not found 404 File is correctly uploaded, but not served


I did python3 manage.py collectstatic enter image description here with no result



Here's .htaccess file in the domain folder: enter image description here

# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION BEGIN
PassengerAppRoot "/home/username/domains/domain.com/djangoapp"
PassengerBaseURI "/"
PassengerPython "/home/username/virtualenv/domains/domain.com/djangoapp/3.7/bin/python"
# DO NOT REMOVE. CLOUDLINUX PASSENGER CONFIGURATION END


<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{REQUEST_URI} ^/media/
    RewriteRule ^media/(.*)$ /home/username/domains/domain.com/djangoapp/media/$1 [L]

</IfModule>

that i tried adding this rule to, with no result.

Any ideas on what could i try? Or anybody who had simillar problem?

I tried to clear database and migrate it from zero. Tried collecting static. I tried changing rule in .htaccess. I tried running in debug and it worked.

Вернуться на верх