H
H
Horizone012019-11-07 12:29:40
Django
Horizone01, 2019-11-07 12:29:40

I'm making a site on Django, I need to make separate pages for each user. How can this be implemented?

I'm building a Django website using allauth . Faced with the fact that it is necessary to make separate pages for each user.

spoiler
На форуме видел похожий вопрос, но решение не было

I have files:
urls.py
from django.urls import path
from .views import *

urlpatterns = [
    path('user/<int:pk>/', UserProfile.as_view(), name='user-profle'),
]

views.py
from django.shortcuts import render
from django.contrib.auth.models import User
from django.views.generic import DetailView

class UserProfile(DetailView):
    model = User
    template_name = 'HomePage/user-profile.html'

spoiler
Я использую DetailView т.к вроде бы он должен отвечать за вывод отдельных страниц

user-profile.html
<h3>{{ object.first_name }} {{ object.last_name }}</h3>

{% if object.is_active %}
<p>Online</p>
{% else %}
<p>Offline</p>
{% endif %}

When trying to follow the path: 127.0.0.1:8000/user/1 or similar, an error is displayed:

Page not found (404)
Request Method: GET
Request URL: 127.0.0.1:8000/user/1
Raised by: HomePage.views.UserProfile
No user found matching request

I can't figure out why Django can't find the user. Since I just started learning Django, I can assume that I underspecified something in views.py, but what exactly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Tikhonov, 2019-11-07
@Horizone01

And the user such in a DB is?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question