my django chars count project
from django.http import HttpResponse
from django.shortcuts import render
def index(request):
return render(request,'index2.html')
def analyze(request):
#Get the text
djtext = request.GET.get('text', 'default')
# Check checkbox values
removepunc = request.GET.get('removepunc', 'off')
char_c = request.GET.get('char_count', 'off')
#Check which checkbox is on
if removepunc == "on":
punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
analyzed = ""
for char in djtext:
if char not in punctuations:
analyzed = analyzed + char
params = {'purpose':'Removed Punctuations', 'analyzed_text': analyzed}
return render(request, 'index.html', params)
elif(char_c=='on'):
analyzed=''
for char in djtext:
analyzed=len(djtext)
params = {'purpose': 'char counter site welcome ', 'analyzed_text': analyzed}
return render(request, 'index.html', params)
and in 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('analyze', views.analyze, name='analyze'),
Comments
Post a Comment