Website Made By me thorugh Django

 Views.py File

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')
    print(djtext)
    #checkbox values
    removepunc=request.POST.get('removepunc','off')
    fullcap =request.POST.get('fullcap','off')
    lowercase =request.POST.get('lowercase','off')
    newline =request.POST.get('newline','off')
   

    analyzed  = djtext
    #checking wich chcekbox is on
    if removepunc == "on":
        punctuations = '''!()-[]{};:'"\,<>./?@#$%^&*_~'''
        analyzed = ""
        for char in djtext:
            if char not in punctuations:
                analyzed = analyzed+ char
        params = {'purpose' : 'Punctuations' , 'analyzed_text' : analyzed}
        djtext = analyzed
        #return render(request , 'analyze.html' , params)
   
   
    if (fullcap == "on"):
        analyzed = ""
        for char in djtext:
            analyzed = analyzed + char.upper()
        params = {'purpose' : 'Changed to CAPITALIZE' , 'analyzed_text' : analyzed}
        djtext = analyzed
        # return render(request , 'analyze.html' , params)
   
    if(newline == "on"):
        analyzed = ""

        for char in djtext:
            if newline != "\n" and char!="\r":
                analyzed = analyzed + char
        params = {'purpose' : 'Removed New Line' , 'analyzed_text' : analyzed}
        djtext = analyzed
   
   
    if (lowercase == "on"):
        analyzed = ""
        for char in djtext:
            analyzed = analyzed + char.lower()
        params = {'purpose' : 'Changed to lowercase' , 'analyzed_text' : analyzed}
        djtext = analyzed
       

    if(removepunc != "on" and newline!="on" and fullcap!="on"):
        return HttpResponse("please select any operation and try again")

    return render(request , 'analyze.html' , params)



Index.HTML file


<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

    <title>Text Utils</title>
  </head>
  <body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
  <a class="navbar-brand" href="http://127.0.0.1:8000/">TextUtils.in</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNavDropdown">
    <ul class="navbar-nav">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="www.codewithharry.com">About Us</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Contact Us</a>
      </li>

    </ul>
  </div>
  <form class="form-inline">
    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
  </form>
</nav>


<div class="alert alert-success alert-dismissible fade show" role="alert">
  <strong>Welcome to TextUtils!</strong> You can do anything with your text here!
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">×</span>
  </button>
</div>


<div class="container">

  <form action='/analyze' method='post'> {% csrf_token %}



  <div class="form-group">
    <label for="exampleFormControlTextarea1">Enter your text here and let Text Utils do the magic</label>
    <textarea class="form-control" name='text' id="exampleFormControlTextarea1" rows="9"></textarea>
  </div>

<div class="custom-control custom-switch">
  <input type="checkbox" name="removepunc" class="custom-control-input" id="customSwitch1">
  <label class="custom-control-label" for="customSwitch1">Remove Punctuations</label>
</div>

  <div class="custom-control custom-switch">
  <input type="checkbox" name="fullcap" class="custom-control-input" id="customSwitch2">
  <label class="custom-control-label" for="customSwitch2">UPPERCASE</label>
</div>

  <div class="custom-control custom-switch">
  <input type="checkbox"  name="newline" class="custom-control-input" id="customSwitch3">
  <label class="custom-control-label" for="customSwitch3">New Line Remover</label>
</div>

  <div class="custom-control custom-switch">
  <input type="checkbox"  name="extraspaceremover" class="custom-control-input" id="customSwitch4">
  <label class="custom-control-label" for="customSwitch4">Extra Spaces Remover</label>
</div>


<div class="custom-control custom-switch">
  <input type="checkbox"  name="lowercase" class="custom-control-input" id="customSwitch5">
  <label class="custom-control-label" for="customSwitch5">lowercase</label>
</div>






<button type="submit" class="btn btn-dark mt-2">Analyze Text</button>
    </form>
</div>


    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
  </body>
</html>

Analyze.HTML File


<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">

    <title>Text Utils</title>
  </head>
  <body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
  <a class="navbar-brand" href="#">TextUtils.in</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNavDropdown">
    <ul class="navbar-nav">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">About Us</a>
      </li>
      <li class="nav-item">
        <a class="nav-link" href="#">Contact Us</a>
      </li>

    </ul>
  </div>
  <form class="form-inline">
    <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
  </form>
</nav>


<div class="alert alert-success alert-dismissible fade show" role="alert">
  <strong>Success!</strong> Your Text Has Been Analyzed !
  <button type="button" class="close" data-dismiss="alert" aria-label="Close">
    <span aria-hidden="true">×</span>
  </button>
</div>


<div class="container">
    <h1>Analyzed  - {{purpose}}</h1>
    <pre><p>{{analyzed_text}}</pre></p>
</div>


    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
  </body>
</html>





URLS.PY File



"""textutils URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/4.0/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""

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')
   
]


   

Post a Comment

Previous Post Next Post