Saturday, July 10, 2021

django - homepage - fetch form textarea value from template to views

 template - index.html:

<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>template is working</title>
<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>

from . import views
urlpatterns = [
path('',views.index, name="index"),
path('about/',views.about, name="about"),
path('textAnalyze',views.textAnalyze, name="textAnalyze")

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')
return HttpResponse(ttext)

web page:

suppose you entered "abcd" in the textarea, then it will go to the and print the inputted data.

No comments:

Post a Comment

Featured Post

11g to 12c OSB projects migration points

1. Export 11g OSB code and import in 12c Jdeveloper. Steps to import OSB project in Jdeveloper:   File⇾Import⇾Service Bus Resources⇾ Se...