0
I am starting my studies in Django, in a CRUD, I created a single form that I would like to use for both creation and change.
I would like to change the text of the button depending on the function to be assigned to the form. In Laravel I checked if the object passed was empty to know if it is creation or change.
In Django I did so, in views.py I went through the render the value of Submit
return render(request, 'form.html', {'form':form, 'btn_submit': 'Cadastrar'})
and
return render(request, 'form.html', {'form':form, 'btn_submit': 'Alterar'})
In html I simply used the value with an interpolation
<!-- form.html -->
<input type="submit" value="{{ btn_submit }}">
I would appreciate the help, if you could point out to me best methods or best practices, it would be very helpful in my learning. Thank you.
your form will be literally the same in both templates? in the change template you will not pass the object, for example?
– Murilo Sitonio
@Murilositonio Yes, the same form for both. When it comes to change, the already filled object is passed.
– Ewerton Belo