0

when i create my form entirely in HTML, how to access the form data in views.py? I want to create a form entirely in HTML without using django form class. When i have done, how to access the form field data in the views.py?. I want to use the data at backend. Please help me

<html>
<head>
 <title>
 HTML forms
 </title>
</head>
<body>

<p> This is a simple form</p>
<form action="" method="post">
{% csrf_token %}
 <fieldset>
 <legend> Personal Information</legend>
 <label for="name">contact_name:<br></label>
 <input type="text" name="contat_name" id="name"><br> 
 <label for="email">contact_email:<br></label>
 <input type="email" name="email" id="email" required placeholder="[email protected]"><br>
 <label for="content">content:<br></label>
 <textarea name="content" rows="10" cols="30">
 </textarea>
 <br>
 <input type="submit" value="submit">
 </fieldset>
 </body>
 </html>

this is my HTML form i want to access the contact_name and contact_email in views.py. how to access the data?

def htmlform(request):
if request.method=="POST":
    print request.POST.get("contact_name")      
return render(request,"htmlform.html")

when i used request.POST.get("contact_name") it returns nothing.

3
  • Show a minimal reproducible example Commented Feb 21, 2017 at 5:28
  • please see the edited field Commented Feb 21, 2017 at 7:56
  • sorry everyone. its because of spelling mistake. i have typed contat_name instead for contact_name in HTML file Commented Feb 21, 2017 at 9:16

2 Answers 2

1

In the Html you've give name as "contat_form" and in the views.py you're trying to access the name as "contact_form"

Sign up to request clarification or add additional context in comments.

Comments

0

This is because in your views.py you are trying to access contat_form whereas the actual field name in the html form is contact_form. Otherwise your method is correct.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.