Question

I am trying to upload a user-generated image and then display in on my django web app. The image is getting uploaded to the server but I am having trouble displaying it.

models.py

image = models.ImageField(blank=True, null=True, max_length=255, upload_to="images/")

settings.py

MEDIA_ROOT = '/home/user/webapps/static/'
MEDIA_URL = 'http://user.webfactional.com/static/'

As an example, say I upload I file named Finland.gif. I can see the file uploaded. However when I look at the source, I see the source of the image as "www.foo.com/accounts/profile/images/Finland.gif" and not the static image url which should be "http://user.webfactional.com/static/images/Finland.gif". Any advice on how I should fix this?

Was it helpful?

Solution

userprofile.image.url gives you the full url to the image

OTHER TIPS

Just solved it... I need to include:

http://user.webfactional.com/static/{{userprofile.image}}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top