python - Django 从 html 表单中检索数据
问题描述
这是我的 html 表单
<form action="#about" method="POST">
{%csrf_token%}
<h2>Signup today</h2>
<input type="text" name="name" class="form-control" placeholder="Full name" required="">
<input type="email" name="email" class="form-control" placeholder="Your email address" required="">
<input type="password" name="password" class="form-control" placeholder="Your password" required="">
<button class="submit-btn form-control" id="form-submit">Get started</button>
</form>
这是views.py
def Student(request):
if request.method=="POST":
print('this post')
name =request.POST['name']
email =request.POST['email']
print(name, email)
return render(request,'#about')
这是我的 urls.py
from django.urls import path
from . import views
urlpatterns = [
path('',views.index, name='index.html'),
path('',views.Student, name="#about"),
]
我是 Django 的新手,我在过去的 24 小时里试图做到这一点,它没有显示任何错误,但它没有打印 views.py 中的任何内容,也没有检索表单数据,谁能向我解释我做错了什么以及如何正确地将html数据表单检索到django?非常感谢您!
解决方案
你的按钮需要type="submit"
这样:
<button class="submit-btn form-control" id="form-submit" type="submit">Get started</button>
推荐阅读
- javascript - Dropbox:使用 JavaScript 将文件上传到公共文件请求
- apache-spark - 如何计算文本输入文件中数字的平均值?
- css - 移动屏幕尺寸的复选框(输入)高度和宽度变化?
- python - Python - 获取列表中的每个项目并将其添加到整数
- node.js - Node JS - Pusher 触发器不起作用
- uitableview - 当用户滚动时,Tableviewcell 中的 UISwitch 状态会重置 - Swift
- perfview - PerfView 的 Metric/Interval 大于 1?
- android - android studio中的节点json
- git - Git 提交消息动词
- pcap - 如何读取 pcap 文件,按 IP 地址和端口过滤,然后将数据写入另一个文件