Forums

File upload directory issue

Hello,

I've got a model with an ImageField:

photo = models.ImageField(upload_to="static/home/images/", null=True, blank=True, validators=[file_size])

And to show that image in the template, I use:

<img src="/{{ content.photo }}" class="img-responsive" style="max-width: 980px;">

Which works fine on my computer, and the images uploaded before (model instances created on my local computer) are shown on PythonAnywhere without issue.

However, when I use the same code on PythonAnywhere, image is not uploaded to the correct directory and not shown. Instead of

/home/steerr/steerr/static/home/images

it is uploaded to

/home/steerr/static/home/images

(My user and project name are both "steerr"). So I changed my model as:

upload_to="steerr/static/home/images/"

Now the files are uploaded to the correct folder. But they are still not displaying on html because

{{ content.photo }}

is now

steerr/static/home/images/image.jpg

...with non-existent URL

http://steerr.pythonanywhere.com/steerr/static/home/images/image.jpg

Whereas it's expected to be

static/home/images/image.jpg

...with the correct URL

http://steerr.pythonanywhere.com/static/home/images/image.jpg

It's a bit confusing, sorry.

Any suggestion or feedback will be welcomed and greatly appreciated.

And

try changing your working directory for your webapp. (under configs in your webapps tab)

It worked, thank you!