[Django]-Is it a good practice to save images in the backend database in mysql/django?

1đź‘Ť

âś…

No.Not good, especially as it scales.

https://docs.djangoproject.com/en/1.9/howto/static-files/deployment/#serving-static-files-in-production

When you think about what happens in the request/response cycle you’ll know that your python scripts get interpreted by some modules. So if you’re using apache for instance, mod_wsgi could be doing this work.
Usually, you don’t want your static files being served by this same process because that is not very efficient, static files being static. In a typical scenario, you’ll want a very fast web server, say nginx serving your static content without “thinking”. This delegation gives a very efficient and scalable design. As @Anentropic said, you could choose to host static media on a CDN.

👤keni

2đź‘Ť

in short: no.

use Django’s built in ImageField and have your webserver serve the files from disk.

Alternatively you can use ImageField with a custom storage backend such as django-storages and put the files up on e.g. Amazon S3 and have them served from there (maybe adding something like CloudFront CDN in front)

👤Anentropic

1đź‘Ť

The best way to do this is to store the images in your server in some specific, general folder for this images. After that you store a string in your DB with the path to the image that you want to load. This will be a more efficient way to do this.

👤acostela

Leave a comment