【问题标题】:Save a raw html form django保存原始 html 表单 django
【发布时间】:2018-08-09 11:18:40
【问题描述】:

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

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

【问题讨论】:

    标签: python django forms


    【解决方案1】:

    【讨论】:

      【解决方案2】:

      如果你有一个模型一个模型表格:

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-02-26
        • 2019-10-04
        • 1970-01-01
        • 2014-05-19
        • 2017-04-18
        • 2010-10-10
        相关资源
        最近更新 更多