1👍
I’m confused when you say the following:
I was expecting the Form that is linked to the model to upload it to
the same location.
If you save an instance of your model directly with that ImageField
, then the file you saved should end up in your MEDIA_ROOT
.
This is how Django’s FileField
s work by default: they do not send things to STATIC_ROOT
.
Staticfiles are explicitly for site-content, not user-uploaded things.
You can’t even set your STATIC_ROOT
and MEDIA_ROOT
to be the same directory, because they serve different purposes and Django’s settings-checker will throw an error if so. Here’s that error in the code:
if ((settings.MEDIA_ROOT and settings.STATIC_ROOT) and
(settings.MEDIA_ROOT == settings.STATIC_ROOT)):
raise ImproperlyConfigured("The MEDIA_ROOT and STATIC_ROOT "
"settings must have different values")
I think a better question is: why are you creating a model that you want to use to store staticfiles?
Source:stackexchange.com