J'essaie de soumettre un formulaire, mais j'obtiens l'erreur "variable locale 'routingForm' référencée avant l'assignation".merci de m'aider à résoudre ce problème.
*****forms.py*****
from django import forms
class routingForm(forms.Form):
areaDigit = forms.CharField(label='areaDigit', max_length=100)
product = forms.CharField(label='product', max_length=100)
*****views.py*****
from django.shortcuts import render
from .forms import routingForm
# Create your views here.
from django.http import HttpResponse,HttpResponseRedirect
from .models import Product,Routing_Dest_Area
def get_route_list(request):
#areaDigit= request.POST.get('areaDigit', False)
#data=Routing_Dest_Area.objects.filter(areaDigit_pk=request.POST['areaDigit'])
if request.method == "POST":
#Get the posted form
routingForm = routingForm(request.POST)
if routingForm.is_valid():
areaDigit = routingForm.cleaned_data['areaDigit']
else:
MyLoginForm = routingForm()
return render(request, 'routing/test.html',{'areaDigit':areaDigit})
*****home.html*****
<form method="POST" action="{% url 'get_route_list'%}" id="routingForm" name="routingForm">
{% csrf_token %}
<div class="form-content">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Area String *"
name"areaDigit" id="areaDigit" value="{{areaDigit}}"/>
</div>
</div>
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="sel1">Select list (select one):</label>
<select class="form-control" id="Product" name="product">
<option> 1</option>
<option> 21</option>
</select>
</div>
</div>
</div>
<button type="submit" class="btnSubmit">Submit</button>