我正在 Django 中做一个项目。在路线 /players
中,我的数据库中有所有玩家的列表。在每个玩家的卡片上,我希望有一个链接,可以将我重定向到玩家个人资料,例如 /players/username
。我尝试了一些 URL 参数,但经过一些尝试后,我需要一些帮助。我知道如何在 Node 中执行此操作,但在 django 中对我来说似乎有点复杂。
我收到了这个错误
Reverse for 'player-profile' with no arguments not found. 1 pattern(s) tried: ['players/(?P<username>[^/]+)/$']
这是我在 player.html 中每张球员卡上的链接
<a href="{% url 'player-profile' %}" class="btn btn-primary">Profil</a>
这是 urls.py 中的 URL 模式
path('players/<username>/', views.player_profile, name='player-profile')
这是views.py中的player_profile函数
def player_profile(request, username):
return render(request, 'blog/player_profile.html```