'How to fill form fields since HTML
I have been looking for information on the web about how set values in forms of django but it has been really difficult. I need to put "Inicio" in the field "Origen_del_Circuito" after pushing the button, I have this code:
Forms.py
class CargaElectricaForm(forms.Form):
Circuito=forms.CharField(label='Circuito', max_length=200)
Origen_del_Circuito=forms.CharField(label='Origen del Circuito', max_length=200 )
views.py
def bajatension(request):
if request.method=="POST":
form=CargaElectricaForm(request.POST)
if form.is_valid():
#form.save()
c="Inicio"
return render (request, 'SizingWires/lowvoltage.html',{'form':form,'c':c})
else:
form=CargaElectricaForm()
return render (request, 'SizingWires/lowvoltage.html',{'form':form})**
lowvoltage.html
<form method="post" >
{% csrf_token %}
<table>
{{form.as_table}}
</table>
<input type="submit"> Calculator</button>
<input type="text" value="{{c}}">
</form>
It doesn't work because it creates a new input and I need to use the field "Origen_del_Circuito". How can I access to the fields of my form since HTML (file lowvoltage.html) to put the value of "c"? I know the method "initial" however I need to put the value after of pushing the button.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|