How To Show User Profile To Everyone By Link! in Django

怎甘沉沦 提交于 2019-12-12 06:59:38

问题


How To Show User Profile To Everyone By Link! in Django

I Want To Show User Profile To Everyone for-example if someone type this in browser domain.com/profile/1

Then Our First User Profile Want To Show

But it's showing blank

It's showing when user login but we need to show to everyone

Here is my detail.html

{% extends 'base.html' %}
{% block body_block %}

<h1 class="posttitle">{{user.username}}</h1>

{% endblock %}

Here is my Views.py

def profile_detail(request,pk):
    model = get_object_or_404(User, pk=pk)
    return render(request,'profile_detail_view.html')

If You Need More Files Like Model,Views,Url Something Let me down in comment i will update my question

Any Help Will Be Appreciated

Thanks!!


回答1:


You are not passing the user instance to the detail.html .

def profile_detail(request,pk):
    user = get_object_or_404(User, pk=pk)
    return render(request,'profile_detail_view.html',{'user':user})



回答2:


I am not sure if it is typo or intentional but in your question you have mentioned template name as detail.html however your view is rendering a different template profile_detail_view.html.

Also I see you have not passed any context data to the template, so you need to fix that and finally please ensure your urls.py is setup properly to serve this route.

def profile_detail(request,pk):
    user = get_object_or_404(User, pk=pk)
    return render(request,'detail.html', {'user':user})


来源:https://stackoverflow.com/questions/58812153/how-to-show-user-profile-to-everyone-by-link-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!