【发布时间】:2017-02-21 05:23:52
【问题描述】:
当我完全用 HTML 创建表单时,如何访问 views.py 中的表单数据? 我想在不使用 django 表单类的情况下完全用 HTML 创建一个表单。完成后,如何访问views.py 中的表单字段数据?我想在后端使用数据。请帮帮我
<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>
这是我想要访问views.py 中的contact_name 和contact_email 的HTML 表单。如何访问数据?
def htmlform(request):
if request.method=="POST":
print request.POST.get("contact_name")
return render(request,"htmlform.html")
当我使用 request.POST.get("contact_name") 它什么都不返回。
【问题讨论】:
-
显示一个最小的可重现示例
-
请查看已编辑的字段
-
对不起大家。这是因为拼写错误。我在 HTML 文件中输入了 contat_name 而不是 contact_name
标签: python-2.7 django-forms forms