I have built a small web application that will get the data from a HTML table and dump it into sqlite database. When I use the POST method to capture a particular cell value, it returns none. Could someone please help me how to get the data from the table I created below in table.html ? Initially I am just trying to print the value of the element "name", later on I will add it to DB. I want the output as ["name1","name2"]
models.py
from django.db import models
class people(models.Model):
Company = models.TextField()
Contact = models.TextField()
Country = models.TextField()
def __str__(self):
return self.Contact
urls.py
from django.contrib import admin
from django.urls import path, include
from . import views
urlpatterns = [
path('', views.getvalue, name='myapp'),
]
views.py
from django.shortcuts import render
def home(request):
return render(request, 'myapp/table.html')
def getvalue(request):
if request.method == "POST":
value = request.POST.get("cellvalue")
print("The values is", value, request.method)
return render(request, 'myapp/table.html')
table.html
<html>
<head>
</head>
<body>
<form role="form" action="getvalue", method="post">{% csrf_token %}
<input type="submit" value="Update DB" />
<table>
<tr>
<td name='cellvalue'>name1</td>
<td name='cellvalue'>name2</td>
</tr>
</table>
</form>
</body>
</html>