簡體   English   中英

其他用戶的個人資料沒有顯示,它只顯示當前用戶名。 如何顯示其他用戶的個人資料?

[英]Other user's profile is not showing, It is showing only current user name . How to display other user's profile?

我正在創建一個 web 應用程序,我希望它通過用戶的帖子顯示其他用戶的個人資料。 我的意思是當用戶單擊其他用戶的個人資料以查看其他用戶的信息時,它將顯示其他用戶的個人資料。 我已經嘗試了所有方法,但是單擊帖子后它會顯示當前用戶信息的名稱。

請幫助我。 非常感謝您。 我真的很感激你的幫助。

這是我的代碼:-

視圖.py

def post_profile(request,username):
    poste = Profile.objects.get(user=request.user)
    context = {'poste':poste}
    return render(request, 'mains/post_profile.html', context)

模型.py

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE,default='',unique=True)
    full_name = models.CharField(max_length=100,default='')
    date_added = models.DateTimeField(auto_now_add=True)

請幫幫我,我不知道問題出在哪里

你可以試試這個:

創建配置文件 url 並傳遞user_id參數。

網址.py

from django.urls import path

urlpatterns =[
    ....
    path('profile/<int:user_id>', views.show_profile, name='show_profile'),
]

現在創建一個視圖並將帶有request參數的user_id參數傳遞給它。

def show_profile(request, user_id):
    poste = Profile.objects.get(user=user_id)
    context = {'poste': poste}
    return render(request, 'mains/post_profile.html', context)

現在在模板中顯示用戶配置文件。

暫無
暫無

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

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