如何将模板的字段与forms.py和views.py连接,以便在模板字段中传递的值可以通过函数

时间:2018-10-12 11:24:03

标签: python django

我是django的新手。我使用django进行登录和注册页面。在此,我有名为login.html的模板文件。在注册中,我指定了名称,电子邮件和密码字段。现在我的问题是如何以表格形式连接名称字段的那些值.py和views.py。我没有在form.py中写什么,为什么我们要使用它

我已经尽力了。但是不知道它是否正确。

login.html

<input type ="text" placeholder="name" id="name" name ="name" onblur="name_check(this.value)" style="margin-bottom: 05px;" required />
        <span id="errorname"style="color: red;"></span>
        <input type ="email" placeholder="email id" id="email" name="email" onblur="email_check(this.value)" style="margin-bottom: 05px;" required />
        <span id="erroremail"style="color: red;"></span>
        <input type ="password" placeholder="password"id="password-input-0" name="password" onblur="password_form(this.value)" style="margin-bottom: 05px;" required />
        <span id="errorpassword"style="color: red;"></span>
        <input type ="password" placeholder="confirm password"  id="password-input-1" name="confirm_password" required/>
      <button type="submit" onclick="password_form(); name_check(); email_check();">sign up</button>
        <p style="color:#6F53C3;font-family:cambria;"class="message">Already Registered? <a href="#"> login </a>

views.py

def StudentRegister(request):
    form_var = form.StudentRegister()

    if(request.method == "POST"):
        form_var = form.StudentRegister(request.POST)

        if(form_var.is_valid()):
            Student_Name1 = request.POST['name']
            Email1 = request.POST['email']
            Password1 = request.POST['password']
            Confirm_PassWord1 = request.POST['confirm_password']

            if(Password1 == Confirm_PassWord1):
                form_var.save(commit = True)

                count = AddEnquiry.objects.filter(Student_Name=Student_Name1).count()

                return render(request,"DashBoard.html",{'count':count})
    return render(request,"login1.html",{'form':form_var})

0 个答案:

没有答案