Question

I am trying to insert values into postgress for a simple registration form but it is not inserting the values into the database. I tried this code.

.HTML

 <form id="form_id" method="post">
{% csrf_token %}
 <h1>Registration</h1>
<body>
  <table class="center">
    <tr>
   <td>Name:<input type="text" id="nm_id"></td>
    </tr>
   <tr><td>Address:<input type="text" id="ad_id">
       </td>
       </tr>
   <tr><td>Email:<input type="text" id="em_id"></td></tr>
  <tr><td> Mob No:<input type="text" id="mo_id"></td></tr>

    </table>


 <input type="submit" id="sub_id">

 </form>

View.py

def dc(request):
    n=request.POST.get["Name"]
    ad=request.POST.get["Add"]
    em=request.POST.get["Email"]
    m=request.POST.get["mo"]
    queryset1=registration.objects.values("n")
    queryset2=registration.objects.values("ad")
    queryset1=registration.objects.values("em")
    queryset1=registration.objects.values("m")
    return render(request,'demo1.html')

Models.py

class registration(models.Model):
    Name = models.CharField(max_length=255)
    Add = models.CharField(max_length=255)
    email = models.CharField(max_length=400)
    mo = models.CharField(max_length=400)

but its not work properly can anybody helpme for registration of these fields?

Was it helpful?

Solution

You need to create and save the instance.

new_user = registration(Name=n,Add=ad,email=em,mo=m)
new_user.save()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top