urls.py:
from django.contrib import admin
from django.urls import path
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.index, name="index"),
path('index',views.index,name="index"),
path('removePunctuation',views.removePunc,name="removePunctuation")
]
views.py
def index(request):
# return HttpResponse("Hello")
return render(request,'index.html')
from django.http import HttpResponse
from django.shortcuts import render
def removePunc(request):
text=request.GET.get('text','default')
check=request.GET.get('removepunc','off')
if check == "on":
puncList= '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
newText=''
for char in text:
if char not in puncList:
newText=newText + char
return HttpResponse(newText)
else:
return HttpResponse(text)
index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>template is working</title>
</head>
<body>
<h1>Welcome to text analyzer. please enter your text.</h1>
<form action="/removePunctuation" methlod="get">
<textarea name="text" style="margin: 0px; width: 1307px; height: 111px;"></textarea><br/>
<input type="checkbox" name="removepunc">Remove Punctuation<br/>
<button type="submit">Analyze Text</button>
</form>
</body>
</html>
Web pages:
You can create another template and show the removed punctuation text there.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Analyzing Your Text...</title>
</head>
<body>
<h1>Your Analyzed Text - {{ purpose }}</h1>
<p>
{{ analyzed_text }}
</p>
</body>
</html>
params = {'purpose': 'Removed Punctuations', 'analyzed_text': newText}
return render(request, 'analyze.html', params)