On Sep 24, 2017 11:55 AM, "yingi keme" <yingikeme@gmail.com> wrote:
Okk. I will like to know how to set the MEDIA_ROOT and MEDIA_URL.?And then, my images are uploaded to a directory named 'img' inside my static files directory. Does it affect how you set the MEDIA_ROOT and MEDIA_URL?
Yes. The location you've chosen for these images is likely incorrect, or at the very least, impractical.
By default, an image file associated with a models.ImageField is stored in MEDIA_ROOT/<image_name> and not in your STATIC directory.
The files within your STATIC directory should not change in production, and ideally should be served by your web server directly and not through Django. STATIC is for the files needed for the site structure such as CSS, JavaScript, logo images, etc. End-user files should not be placed there.
MEDIA_ROOT should be set to a location that can be written to by the web server that is not in any of your STATIC locations (Django will complain if it is). This value is an absolute path in the server file system.
MEDIA_URL should be set to whatever URL path prefix should be used to trigger the web server to provide a file. This value is something that will prefix the path to the file in the URL used by the browser.
In you case, using a MEDIA_URL value of '/media/', an image URL might look like http://example.com/media/img/my_image.jpg. The web server would then map that request to download /<MEDIA_ROOT>/img/my_image.jpg.
See these links:
So, nobody can really "tell" you what they should be set to since it tends to be environment specific.
-James
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXDVusovsDs61MNDEU%2B3PiYQvvWj1jPhqWWfUgb0M-XPQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment