I am working on a django project. Even when the condition is True, it doesn’t go to the elif statement My code :-
# views.py
# I have created this file - Harry
from django.http import HttpResponse from django.shortcuts import render
def index(request): return render(request, 'index.html')
# return HttpResponse("Home")
def analyze(request): #Get the text
djtext = request.POST.get('text')
print('got data', djtext)
removepunc = request.POST.get('removepunc', 'off')
fullcaps = request.POST.get('fullcaps', 'off')
newlineremover = request.POST.get('newlineremover', 'off')
extraspaceremover = request.POST.get('extraspaceremover', 'off')
print(fullcaps=='on')
# return HttpResponse(f'{djtext}, {removepunc}')
# analyzed = djtext
purpose = ''
if removepunc == 'on':
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
analyzed = ''
for char in djtext:
if char not in punctuations:
analyzed += char
djtext = analyzed
purpose += 'Removed Punctuations '
print('punctionatol', djtext)
elif fullcaps == 'on':
print("Came here full of caps")
purpose += 'Capitalized everything '
analyzed = djtext.upper()
djtext = analyzed
print('Full caps', djtext)
elif newlineremover == 'on':
analyzed = ''
for char in djtext:
if char != '\n':
analyzed += char
purpose += 'Removed new lines'
djtext = analyzed
print('new oiens', djtext)
elif extraspaceremover == 'on':
analyzed = ''
for index, char in enumerate(djtext):
if not (djtext[index] == ' ' and djtext[index + 1] == ' '):
analyzed = analyzed+char
djtext = analyzed
print('spaxes', djtext)
else:
purpose = 'No task given'
return HttpResponse("Choose a task to be performed and try again")
djtext = analyzed
print('final dj sfu k text', djtext)
params = {
'purpose':purpose,
'analyzed_text':djtext
}
#Analyze the text
return render(request, 'analyze.html', params)
I am very frustrated help Thanks