django .urls.exceptions.NoReverseMatch несмотря на установку всех параметров - PullRequest
0 голосов
/ 24 февраля 2020

Так что я думаю, что я все правильно добавил, с шаблонами URL, представлениями и страницей html, но я не уверен, что пошло не так.

path('hero/<int:hero_id>/', manage_hero, name="manage_hero"),
@login_required
def manage_hero(request, hero_id):
    context = {'hero_bar' : True}
    profile = UserProfile.objects.get(user=request.user)
    hero = get_object_or_404(Accskill, id=hero_id)
    if not profile.player.guid == hero.guid:
        return render(request, "dashboard/no_permission.html", context={'redirect' : reverse("dashboard:dashboard")})
    context['hero'] = hero
    context['form'] = ModifyHeroForm(hero=context['hero'])
    return render(request, "hero/hero.html", context=context)
<td><a href="{% url 'hero:manage_hero' hero_id=hero.ID %}" class="btn btn-outline-primary" role="button" aria-disabled="true">管理英雄</a></td>

Наконец, работает реверс

reverse('hero:manage_hero', kwargs={'hero_id':4})
'/heroes/hero/4/'

И ошибка

django.urls.exceptions.NoReverseMatch: Reverse for 'manage_hero' with no arguments not found. 1 pattern(s) tried: ['heroes/hero/(?P<hero_id>[0-9]+)/$']
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...