i wanted to make simple page with two input forms first one for posting data into file second for taking index and deleting data from file and both of them working independent but so far i can only use first form like the second one its not even reached not a single method from second form is completed here goes the code:
###############
#Views.py
class HomeView(TemplateView):
template_name = 'index/num.html'
def get(self, request):
form = AddForm()
form2 = DeleteForm()
result = printResult()
return render(request, self.template_name, {'form': form, 'form2': form2,'result': result})
def post(self, request):
result = "result"
####____add option###################
if request.method == 'POST':
form = AddForm(request.POST)
form2 = DeleteForm(request.POST)
if form.is_valid():
text = form.cleaned_data['post']
if (re.match("[0-9]+", str(text))):
text = text
else:
text= None
result = addToFile(text)
args = {'form': form, 'form2': form2, 'text': text, 'result': result }
return render(request, self.template_name, args)
##########
###____Delete option#######
if form2.is_valid():
index = form2.cleaned_data['dell']
result = DeleteIndexFromFile(index)
args2 = {'form': form, 'form2': form2, 'text': index, 'result': result }
return render(request, self.template_name, args2)
##########
#forms.py
from django import forms
class AddForm(forms.Form):
post = forms.CharField(required = False)
class DeleteForm(forms.Form):
delete = forms.IntegerField(required = False)
#num.html
<div class="container">
<p>
<form method="post">
{% csrf_token %}
{{ form }}
<button type="submit">Submit</button>
</form>
<form method="delete" >
{% csrf_token %}
{{ form2 }}
<button type="submit">Delete</button>
</form>
</p>
<p>
<h4>Data: {{ text }}</h4>
<h4>{{ result }}</h4>
</p>
</div>