Python 2.7 如何在views.py中访问HTML表单中的数据?
当我完全用HTML创建表单时,如何访问views.py中的表单数据? 我想完全用HTML创建一个表单,而不使用django表单类。完成后,如何访问views.py中的表单字段数据?。我想在后端使用数据。请帮帮我Python 2.7 如何在views.py中访问HTML表单中的数据?,python-2.7,django-forms,forms,Python 2.7,Django Forms,Forms,当我完全用HTML创建表单时,如何访问views.py中的表单数据? 我想完全用HTML创建一个表单,而不使用django表单类。完成后,如何访问views.py中的表单字段数据?。我想在后端使用数据。请帮帮我 <html> <head> <title> HTML forms </title> </head> <body> <p> This is a simple form</p> <f
<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="example@example.com"><br>
<label for="content">content:<br></label>
<textarea name="content" rows="10" cols="30">
</textarea>
<br>
<input type="submit" value="submit">
</fieldset>
</body>
</html>
当我使用request.POST.get(“contact_name”)时,它不返回任何内容。这是因为在your views.py中,您试图访问
contat_表单
,而html表单中的实际字段名是contact_表单。否则,您的方法是正确的。在Html中,您将名称命名为“contat\u form”,在views.py中,您尝试以“contact\u form”的形式访问名称。显示一个最小的可重复示例请查看编辑的字段。这是因为拼写错误。我在HTML文件中输入了contat_name作为联系人名称
def htmlform(request):
if request.method=="POST":
print request.POST.get("contact_name")
return render(request,"htmlform.html")