python
  • django
  • settings
  • models
  • imagefield
  • 2012-09-25 36 views 1 likes 
    1

    我想上传用户生成的图像,然后显示在我的django网络应用程序。图像上传到服务器,但我无法显示它。如何使用django正确显示用户生成的图像?

    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/' 
    

    举个例子,说我上传我的文件命名Finland.gif。我可以看到上传的文件。然而,当我看到源代码时,我将该图片的源代码视为“www.foo.com/accounts/profile/images/Finland.gif”,而不是静态图片url,它应该是“http://user.webfactional .COM /静态/图片/ Finland.gif”。有关如何解决这个问题的任何建议?

    +0

    ü可以显示用于显示图像的代码? – Rakesh

    +0

    @Rakesh sharataka

    回答

    2

    userprofile.image.url为您提供了完整的URL,图像

    0

    只是解决了......我需要包括:

    http://user.webfactional.com/static/{{userprofile.image}} 
    
    相关问题