views.py :
def edit(request, news_id): if request.method == 'POST': if form.is_valid(): a = Laba.objects.get(pk=news_id) f = LabaForm(request.POST, instance=a) f.save() return redirect('/LR/') form = LabaForm() return render(request, 'LR/edit.html', {'form': form}) This code is called by clicking on the button:
<form method="post" action="edit/{{result.id}}/">{% csrf_token %}<input type="submit" value="Редактировать данные" /></form> Clicking on the button returns an error:
local variable 'form' referenced before assignment
I understand that the error is related to the form = LabaForm() fragment, but I don’t understand how to fix it.
if form.is_valid(), and then assigned:form = LabaForm(), no? .. - Alekcvp