1

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?

Community
  • 1
  • 1
sharataka
  • 5,014
  • 20
  • 65
  • 125

2 Answers2

2

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

super9
  • 29,181
  • 39
  • 119
  • 172
0

Just solved it... I need to include:

http://user.webfactional.com/static/{{userprofile.image}}
Pedro Romano
  • 10,973
  • 4
  • 46
  • 50
sharataka
  • 5,014
  • 20
  • 65
  • 125