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?
Thanks!
CodePudding user response:
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.