Не удается получить доступ к веб-странице django

я работаю над страницей пользователя на django. я хочу ввести http://127.0.0.1:8000/user/2 и получить свой шаблон, но django говорит The current path, user/2, didn’t match any of these.

Мое мнение:

from django.shortcuts import render
from django.views import generic
from .models import *

def UserPage(request,user_num):
    #get user info
    username = "none"
    posts = []#post("test", "none")
    status = 'aboba'
    return render(
        request,
        'userpage.html',
        context={'username': username, 'posts': posts, 'status': status},
    )

мои урлы:

from django.urls import path
from . import views


urlpatterns = [
    path(r'^user/(?P<user_num>\d+)$', views.UserPage, name='userpage'),
]

Я думаю, что это потому, что вы смешиваете regex path и обычный path, либо избавьтесь от regex, либо используйте re_path

 path('user/<user_num>'
from django.urls import re_path
re_path(r'^user/(?P<user_num>\d+)$'
Вернуться на верх