How to use id in the path?
-
I'm new here. You can tell me how it passes.
id
Totalpath
? Required in transitionhttp://localhost:8000/12/
Receive a page from the participantid 12
In such an option:path('member_id', views.member_detail, name='member-detail')
Here.
views.py
:def member_detail(request, member_id): member = get_object_or_404(Member, id=member_id) return render(request, 'member_detail.html', {'member': member})
I'm getting a mistake.
Using the URLconf defined in firstproject.urls, Django tried these URL patterns, in this order: The current path, 1/, didn’t match any of these.
-
Your urls.py doesn't have an appropriate template.
path('member_id', views.member_detail, name='member-detail'), path('member_id/<int:id>', views.member_detail, name='member-detail'),
In addition, since the beam may be caused without the id parameter, its default value must be corrected:
def member_detail(request, member_id=-1): ...