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