簡體   English   中英

django鏈接到社區中的任何用戶個人資料

[英]django link to any user profile in social comunity

我正在嘗試建立一個虛擬社區,並且我有一個個人資料頁面和一個個人頁面。 在個人資料頁面中,只能看到一個用戶的帖子(選中其用戶的用戶),在個人頁面中,可以看到他的帖子以及他已訂閱的所有帖子(就像在Facebook中一樣)

我如何才能鏈接到一個用戶的個人資料,這讓我有些困惑,我的意思是當任何人單擊用戶名時,它都應鏈接到他的個人資料頁面。 例如,如果某人搜索名稱“ abc”,則結果將是“ abc”,並鏈接到他的個人資料。

如何將鏈接用戶的用戶名或ID傳遞給一個函數? 我的意思是,顯示正在檢查其個人資料的已登錄用戶的個人資料非常容易。但是,如果要訪問另一個用戶個人資料呢?

非常感謝!

您需要一個網址格式:

url(r'^profile/(?P<id>\d+)/$', profile_view, name='profile')

一個看法:

def profile_view(request, id):
    u = UserProfile.objects.get(pk=id) # this is the user who's profile is being viewed.
    # here's your view logic
    # render a user's profile template in the end

在要鏈接到某人的個人資料的每個模板中,可以使用:

<a href="{% url profile u.id %}">{{ u.username }}</a>

假設模板知道您要鏈接為u

您還可以使這種想法適應使用段塞而不是ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM