字段“ id”需要一个数字,但得到了“创建”。请求方法:

时间:2020-08-23 11:55:40

标签: django-forms

我创建了一个表单,用户可以在其中创建团队。首先,创作工作。但是,在确定了团队详细信息视图之后,我无法再创建团队。 这是详细视图:

def team(request, id, **kwargs):
    team = get_object_or_404(Team, id=id)
    if request.method == "POST":
        team.instance.team = team
        return redirect(reverse('team-detail', kwargs={
            'id': team.id
    }))
    context = {
        'team': team,
    }
    return render(request, 'club.html', context)

现在是创建视图:

def team_create_view(request, id):
    title = 'Create'
    form = TeamCreateForm(request.POST or None, request.FILES or None)
    coach = get_coach(request.user)
    if request.method == 'POST':
        if form.is_valid():
            new_team = form.save()
            return redirect(reverse("club", kwargs={'id': form.instance.id }))
    else:
        form = TeamCreateForm()   
    context = {'title': title,'form': form}
    return render(request, "team_create.html", context)

url.py

    path('team/<id>/', team, name='team-detail'),
    path('team/create/', team_create_view, name='team-create'),

0 个答案:

没有答案