i am working on user's page on django. i want to enter http://127.0.0.1:8000/user/2 and get my template but django says The current path, user/2, didn’t match any of these.
my view:
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},
)
my urls:
from django.urls import path
from . import views
urlpatterns = [
path(r'^user/(?P<user_num>\d )$', views.UserPage, name='userpage'),
]
CodePudding user response:
I believe its because you're mixing a regex path and a regular path, either get rid of the regex stuff or use a re_path
path('user/<user_num>'
from django.urls import re_path
re_path(r'^user/(?P<user_num>\d )$'