template - 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="/textAnalyze" methlod="get">
<textarea name="text" style="margin: 0px; width: 1307px; height: 111px;"></textarea>
<button type="submit">Analyze Text</button>
</form>
</body>
</html>
urls.py:
from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('',views.index, name="index"),
path('about/',views.about, name="about"),
path('textAnalyze',views.textAnalyze, name="textAnalyze")
]
views.py:
from django.http import HttpResponse
from django.shortcuts import render
def index(request):
params = {"name":"Sri","role":"develoepr"}
# return HttpResponse("Hello")
return render(request,'index.html',params)
def about(request):
return HttpResponse("<h1>about</h1>")
def textAnalyze(request):
ttext = request.GET.get('text','default')
print(ttext)
return HttpResponse(ttext)
web page:
suppose you entered "abcd" in the textarea, then it will go to the views.py and print the inputted data.
No comments:
Post a Comment