[Fixed]-Displaying one Django database object on a page at a time

1👍

The views.py file must take an argument when you are trying to display a specific profile.

try this:

def person(request, id):
    person = Person.objects.get(pk=id)
    return render(request, 'person/index.html', {'person': person, })

This should do.

Also, you must add an entry in the urls.py file,

url(r'/person/(?P<id>\d+)/$', views.person),
👤v1k45

0👍

Yes, you can do it.

All you have to do is: modify your urls.py to define URL with parameter, extract that parameter in view (it will be passed to view as argument or keyword argument) and extract one person, using get or filter instead of all.

0👍

Just an example

You need to create one more function with name example “profile_data”

views.py

def profile_data(request,userid)
    person_info = Person.objects.get(id=userid)
    person_data = {
    "person_detail" : person_info
     }
    return render(request, 'profile.html', person_data)

url.py

url(r'^profile/(?P<userid>\d+)/$', app.views.profile)

You need to pass the userid to that url,in this way you get that details of that particular user.

👤chandu

Leave a comment