【问题标题】:Reverse for '' with arguments '' and keyword arguments '{}' not found未找到带有参数 '' 和关键字参数 '{}' 的 '' 的反向
【发布时间】:2013-12-07 09:54:29
【问题描述】:

我有网址:

url(r'^tournament/(?P<tournament_id>\d+)/tour/$', chess.views.first_tour, name = 'first_tour'),    
url(r'^tournament/(?P<tournament_id>\d+)/tour/match/(?P<pk>\d+)/$', chess.views.edit_match, name = 'edit_match'),

观看次数:

def first_tour(request, tournament_id):
    ...
    matches = []
    for item in items:
       match = Match.objects.get(...)
       matches.append(match)
    return render(request, 'first_tour.html', {'matches':matches})

def edit_match(request, tournament_id, match_id ):
    pass

一个模板,其中我有一个匹配循环和每个循环:

<a href="{% url 'edit_match' match.pk %}">Enter results</a>

为什么会出现错误:“edit_match”的反向参数“(5L,)”和关键字参数“{}”未找到。出现了吗?

【问题讨论】:

  • 模板的 for 循环中 {{ match.pk }} 的输出是什么?

标签: python django django-templates django-views django-urls


【解决方案1】:

您需要指定 URL 中的所有值:

{% url 'edit_match' tournament_id=... pk=match.pk %}

您目前只为 pk 指定一个值,这意味着 Django 找不到匹配的名为 edit_match 的 URL(即,它有一个未命名的参数)。您的edit_match 有两个命名参数。

【讨论】:

  • 还是不行。它打印: : Reverse for 'edit_match' with arguments '()' 和关键字参数 '{u'pk': 5L, u'tournament': }' not found.
  • @miss_tais 您的参数称为tournament_id,而不是tournament。它们需要与您的 URL 配置相匹配。
猜你喜欢
  • 2010-12-22
  • 2015-08-29
  • 2014-05-29
  • 2013-07-25
  • 2019-11-06
  • 2012-07-08
  • 2019-04-21
  • 2016-06-15
相关资源
最近更新 更多