Django - я всегда получаю свой профиль, когда хочу просмотреть профиль другого пользователя

Я пытаюсь сделать так, чтобы при доступе пользователя к сайту url / имя пользователя, например http://127.0.0.1:8000/destiny/, но при этом вылетает ошибка Profile() got an unexpected keyword argument 'username'. Я пробовал добавлять аргумент имени пользователя в моих представлениях профиля. Я также пытался получить имя пользователя, когда пользователь регистрируется, чтобы использовать его в представлении профиля, но это все равно не работает. Я новичок в django, поэтому я не знаю, откуда берется ошибка

ОБНОВЛЕНИЕ: Другая ошибка теперь исправлена. Но когда я хочу просмотреть профиль других, он всегда возвращает мой собственный профиль

views.py

def UserProfile(request, username):
    user = get_object_or_404(User, username=username)
    profile = Profile.objects.get(user=user)
    url_name = resolve(request.path).url_name
    
    context = {
        'profile':profile,
        'url_name':url_name,
    }

    return render(request, 'userauths/profile.html', context)




#register view
def register(request):
    reviews = Review.objects.filter(status='published')
    info = Announcements.objects.filter(active=True)
    categories = Category.objects.all()
    if request.method == "POST":
        form = UserRegisterForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            username = form.cleaned_data.get('username')

            messages.success(request, f'Hurray your account was created!!')
            new_user = authenticate(username=form.cleaned_data['username'],
                                    password=form.cleaned_data['password1'],
                                    )
            login(request, new_user)
            return redirect('elements:home')
            


    elif request.user.is_authenticated:
        return redirect('elements:home')
    else:
        form = UserRegisterForm()
    context = {
        'reviews': reviews,
        'form': form,
        'info': info,
        'categories': categories
    }
    return render(request, 'userauths/register.html', context)

models.py

class Profile(models.Model):
    user = models.OneToOneField(User, related_name='profile', on_delete=models.CASCADE)
    first_name = models.CharField(max_length=1000, null=True, blank=True)
    last_name = models.CharField(max_length=1000, null=True, blank=True)
    email = models.EmailField(null=True, blank=True)
    phone = models.IntegerField(null=True, blank=True)
    bio = models.CharField(max_length=1000, null=True, blank=True)
    aboutme = models.TextField(null=True, blank=True, verbose_name="About Me")
    country = models.CharField(max_length=1000, null=True, blank=True)
    cover_photo = models.ImageField(default='default.jpg', upload_to="profile_pic")
    image = models.ImageField(default='default.jpg', upload_to="profile_pic")
    joined = models.DateTimeField(auto_now_add=True, null=True)

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)

    def __str__(self):
        return f'{self.user.username} - Profile'

основной проект urls.py

from userauths.views import Profile

urlpatterns = [
    path('admin/', admin.site.urls),
    path('users/', include('userauths.urls')),
    path('<username>/', Profile, name='profile'),

UPDATE: Первая ошибка была исправлена. Это произошло потому, что имя моего профиля UserProfile, а я использовал Profile вместо него.

Теперь я получаю эту ошибку, которая говорит 'function' object has no attribute 'objects'

Full Traceback

System check identified no issues (0 silenced).
January 03, 2022 - 13:16:50
Django version 3.1, using settings 'dexxapikprj.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Internal Server Error: /destiny/
Traceback (most recent call last):
  File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Destiny\Desktop\dexxapik3\DexxaPik\dexxapikprj\userauths\views.py", line 21, in Profile
    profile = Profile.objects.get(user=user)
AttributeError: 'function' object has no attribute 'objects'
[03/Jan/2022 13:16:51] "GET /destiny/ HTTP/1.1" 500 66676
[03/Jan/2022 13:16:52] "GET /favicon.ico HTTP/1.1" 301 0
Not Found: /favicon.ico/
[03/Jan/2022 13:16:52] "GET /favicon.ico/ HTTP/1.1" 404 1736
Internal Server Error: /destiny/
Traceback (most recent call last):
  File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Destiny\Desktop\dexxapik3\DexxaPik\dexxapikprj\userauths\views.py", line 21, in Profile
    profile = Profile.objects.get(user=user)
AttributeError: 'function' object has no attribute 'objects'
[03/Jan/2022 13:16:53] "GET /destiny/ HTTP/1.1" 500 66676
Internal Server Error: /destiny/
Traceback (most recent call last):
  File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "C:\Users\Destiny\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\Destiny\Desktop\dexxapik3\DexxaPik\dexxapikprj\userauths\views.py", line 21, in Profile
    profile = Profile.objects.get(user=user)
AttributeError: 'function' object has no attribute 'objects'
[03/Jan/2022 13:17:02] "GET /destiny/ HTTP/1.1" 500 66676

Вы получили эту ошибку, потому что представление называется UserProfile, а не Profile

Вернуться на верх