python
  • django
  • settings
  • models
  • imagefield
  • 2012-09-25 27 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}} 
    
    相關問題