2

I've implemented a FileField model in my project. I can successfully upload svg files and they save to the desired location.

Within my project, I make heavy use of user uploaded images (JPGs) and they save to the correct location and I can display them in my templates with no issue.

However, when I upload an svg to the FileField and then attempt to display it within the template, the link is broken. The problem is that the correct file path isn't being set within the html

Template:

<img src="{{ account.image }}" />

It should point to the following path:

localhost:8000/media/Users/jimmy/file.svg

But it resolves as the following, which is incorrrect:

localhost:8000/profile/settingspage1/Users/jimmy/file.svg

Essentially, I've I manually append '/media' to the filepath within the template, it works, but I shouldn't have to do this. The filepath should resolve correct.

<img src="/media/{{ account.image }}" />

Any thoughts on what setting could be preventing only filefields from resolving to the correct path within my media folder?

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
Jason Howard
  • 1,464
  • 1
  • 14
  • 43
  • This [question](https://stackoverflow.com/q/57996723/17562044) can help you, one time look at this. – Sunderam Dubey Apr 29 '22 at 10:36
  • Doesn't help at all. Sorry. I'm able to successfully upload an svg file into Django. The problem is that when I attempt to display it in my template, the file path is wrong. – Jason Howard Apr 29 '22 at 10:39

1 Answers1

0

You need to pass the url of image, as it contains the original url which links to all media files.

Try this:

<img src="{{account.image.url}}" />

It will give you desired output.

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40