ImageField url method returns non-Url value - Django

I am developing Django on Windows. I have a model with an image field and use a form to fill it out. Images load without problems. The problem comes when I try to show the uploaded image inside the template by coding this:

<img src ='{{object.image.url}}'/>   

      

(object is an instance of the corresponding model and image is the name of the image field)

However, the image is not displayed as the url method does not return the url, but the path like this:

c: /pp/pm/static/image/xyz.png

What should I do to make it a real URL?

edit:

MEDIA_ROOT and MEDIA_URL settings:

MEDIA_ROOT = 'C:/pp/pm/static/'
MEDIA_URL = '/static/'

      

+1


a source to share


1 answer


I had the same problem. In the model declaration, I changed the value of the "upload_to" parameter from an absolute path to a relative path, this fixes the problem.



+2


a source







All Articles