I built an html form using the <form>
tag and not using built in Django forms. The form asks for name and age. What I want to do is that after the user fills the form, the url of the page is kept same, while the contents of the page are changed to display name and age. How can I do that?
<html>
<head>
<title>Form</title>
</head>
<body>
<form method="post" action="aftersubmit">
{% csrf_token %}
<input placeholder="yourname" name="name">
<br>
<input placeholder="your age" name="age">
<br>
<input type="submit" value="Submit">
</form>
</body>
</html>
from django.shortcuts import render,redirect
# Create your views here.
def formpage(request):
return render(request,'formhtml.html')
def aftersubmit(request):
name = request.POST['name']
age = request.POST['age']
dictionary = {
"name":name,
"age":age
}
print(dictionary)
return redirect('formpage')
My current code keeps the url same but does not modify the contents of the page.