保存原始HTML表单Django

时间:2018-08-09 11:18:40

标签: python django forms

我正在尝试从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

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

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

如果您有模型,则模型为Form:

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()