保存原始 html 表单 django



>我正在尝试从 django 中的原始 html 表单中保存一些用户数据。
我的代码如下所示:

# This is the view -->
if request.method == 'POST':
name = request.POST['name']
email = request.POST['email']
age = request.POST['age']
password = request.POST['password']
# Some validation (But unnecessary for this Question)
# save the form into my user model

所以真正的问题是:如何将姓名、电子邮件、年龄和密码保存到我的数据库中?

我建议你遵循 Django 的官方文档 - 模型表单

如果你有一个模型,一个模型形式:

if request.method =="POST":
form=Form(request.POST) # you need to init form in previous view
if form.is_valid():
#inserte your actions here 
form.save()

最新更新