2017-09-16 26 views
1

我擁有頁面,其中包含系統中所有用戶的列表。列表中的每個用戶顯示三件事:1.他們的個人資料圖片,2.他們的名字,和他們的用戶類型。但是,雖然配置文件圖片顯示,但它不顯示對應於該特定用戶的正確的一個。相反,它會爲網站上的每個用戶顯示當前登錄用戶的個人資料圖片。Django爲個人用戶提供的圖像不顯示

用戶profile_list.html:

{% extends "base.html" %} 

{% block content %} 

    {% for users in userprofile_list %} 
     <a class="user-profile-link user-card" href="{% url 'users:user_profile' users.pk %}"> 
      <img class="profile-pic" src="{%if user.userprofile.profile_pic%}{{user.userprofile.profile_pic.url}}{%endif%}"> 
      <p class="user-card-name">{{ users.first_name }}</p> 
      <p class="user-card-type">{{ users.user_type }}</p> 
     </a> 
    {% endfor %} 

{% endblock %} 

發生了什麼事的圖片: enter image description here

不是我的每一個用戶的圖片大小,應該顯示自己的個人資料圖片,即使我是已登錄的人。

+0

您對'userprofile_list'中的用戶,但是指'user.userprofile.profile_pic.url'(複數與單數)。那麼用戶可能來自其中一個上下文處理器。 –

+0

'user'是誰登錄的,並且被傳遞到每個模板中的上下文,我知道。這意味着它會是你,而你的錯字是什麼導致用戶的照片都是你。這不能回答你的問題,但它應該說明它爲什麼會發生。對於給出的信息,您還有另一個問題對我來說似乎並不明顯。 –

回答

1

您有錯字需要添加s,因爲您的循環變量爲users,看起來您需要刪除userprofile

src="{%if users.profile_pic %}{{ users.profile_pic.url }}{% endif % }" 
<!--   ^^^     ^^^ --> 
+0

現在沒有任何圖片工作 – Garrett

+0

更新了無法嘗試它,如果不幫你,請將你的模型添加到問題 –

+0

是的,我認爲這樣做的工作,謝謝。爲什麼我必須取出'userprofile'? – Garrett