Reputation: 39
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>HELLO</title>
</head>
<body>
<form action="/removepunc", method="get">
<input type="text",name='text' value="Hello,Django" />
<input type="submit">
</form>
</body>
</html>
views.py
from django.http import HttpResponse
from django.shortcuts import render
def index(request):
return render(request,'index.html')
def removepunc(request):
print("Text is :"+request.GET.get('text','default'))
return HttpResponse("Hello")
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('removepunc',views.removepunc,name='rempunc')
]
This is first screen after run the code
When I click on submit in Url it did not show "hello django"
Also in terminal it print default not "hello django"
Upvotes: 0
Views: 932
Reputation: 476709
There is a comma in your <input>
box between "text"
and name
.
The <input>
tag should thus look like:
<input type="text" name="text" value="Hello,Django" />
not:
<input type="text",name='text' value="Hello,Django" />
Upvotes: 1