-
Notifications
You must be signed in to change notification settings - Fork 132
Open
Description
from django . http import HttpResponse
from django.shortcuts import render
def index(request):
return render(request, 'index.html')
def analyze(request):
#Get the text
djtext = request.POST.get('text', 'default')
#check the checkbox
removepunc = request.POST.get('removepunc', 'off')
extraspaceremover = request.POST.get('extraspaceremover','off')
fullcaps = request.POST.get('fullcaps', 'off')
newlineremover = request.POST.get('newlineremover', 'off')
countchar = request.POST.get('countchar', 'off')
numberremover = request.POST.get('numberremover','off')
print(fullcaps)
print(extraspaceremover)
print(removepunc)
print(djtext)
if (removepunc == "on"):
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
analyzed = ""
for char in djtext:
if char not in punctuations:
analyzed = analyzed + char
params = {'purpose': 'Removed Punctuations', 'analyzed_text': analyzed}
djtext = analyzed
if (extraspaceremover == "on"):
analyzed = ""
for index, char in enumerate(djtext):
if not(djtext[index] == " " and djtext[index + 1] == " "):
analyzed = analyzed + char
params = {'purpose': 'EXTRA SPACES REMOVED', 'analyzed_text': analyzed}
djtext = analyzed
if (fullcaps =="on"):
analyzed = ""
for char in djtext:
analyzed = analyzed + char.upper()
params = {'purpose': ' UPPER CASE', 'analyzed_text': analyzed}
djtext = analyzed
if (newlineremover =="on"):
analyzed = ""
for char in djtext:
if char !='\n' and char!='\r':
analyzed = analyzed + char
params = {'purpose': ' NEW LINE REMOVER', 'analyzed_text': analyzed}
djtext = analyzed
if (countchar =="on"):
analyzed = ""
for char in djtext:
analyzed = len(djtext)
params = {'purpose': 'COUNT CHAR', 'analyzed_text': analyzed}
djtext=analyzed
if (numberremover == "on"):
analyzed = ""
numbers = '0123456789'
for char in djtext:
if char not in numbers:
analyzed = analyzed + char
params = {'purpose': 'NUMBER REMOVED', 'analyzed_text': analyzed}
djtext = analyzed
if (removepunc!="on" and fullcaps!= "on" and newlineremover!= "on" and extraspaceremover!= "on" and countchar!= "on" and numberremover!= "on"):
return HttpResponse('Error')
return render(request, 'analyze.html', params)
on running this code it is giving an error
!!!!!!
| Request Method: | POST |
|---|---|
| http://127.0.0.1:8000/analyze | |
| 3.0.6 | |
| IndexError | |
| string index out of range | |
| C:\Users\hp\PycharmProjects\Textutils\Textutils\Textutils\views.py in analyze, line 44 | |
| C:\Users\hp\AppData\Local\Programs\Python\Python38\python.exe | |
| 3.8.3 | |
| ['C:\Users\hp\PycharmProjects\Textutils\Textutils', 'C:\Users\hp\AppData\Local\Programs\Python\Python38\python38.zip', 'C:\Users\hp\AppData\Local\Programs\Python\Python38\DLLs', 'C:\Users\hp\AppData\Local\Programs\Python\Python38\lib', 'C:\Users\hp\AppData\Local\Programs\Python\Python38', 'C:\Users\hp\AppData\Local\Programs\Python\Python38\lib\site-packages'] |
Metadata
Metadata
Assignees
Labels
No labels