简体   繁体   中英

Is it possible to serve media files by Django on Production with static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

I want to use non-static images for my app. Meaning that Admin will be able to upload images (and create articles). Users will have read-only access to articles.

Would in this case it be possible to use function static() on Production to store and serve images?

static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Or still I should use only 3rd party resource for storing/serving the images?

The answer happened to be very simple:

the function

static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

simply won't work with "Debug = false".

That's why it can not be used on Production. Here is a quote from documentation :

This helper function works only in debug mode and only if the given prefix is local (eg /media/) and not a URL (eg http://media.example.com/ ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM