简体   繁体   中英

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

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!!

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})

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})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM