Django Project 8 Inserting data into database from HTML page

preview_player
Показать описание
----------------------------------------
Welcome to Official Tech
---------------------------------------

Django Project 8 Inserting data into database from HTML page

Here we will create a DB
and HTML page
and GETTING data from that HTML page
and Inserting into DB

-----------

from app8 import views

urlpatterns = [
]

---------------------------------------------------------------------------------------------------
-------------
from .models import StudentDetails
# Create your views here.

def indexpage(req):

def newPage(request):
id = request.POST.get("idno1")
na = request.POST.get("name1")
co = request.POST.getlist("course1")
mark = request.POST.get("marks1")
cont = request.POST.get("contact1")

o_ref = StudentDetails(name=na, idno=id, course=co, contact=cont, marks=mark)

-----------------------------------------------------------------------------------------------------

-----------------

# Create your models here.

class StudentDetails(models.Model):
idno = models.IntegerField(primary_key=True)
name = models.CharField(max_length=33)
course = models.CharField(max_length=200)
marks = models.DecimalField(max_digits=10 , decimal_places=5)
contact = models.IntegerField()

for HTML page visit(youtube not allow HTML code):

Рекомендации по теме
Комментарии
Автор

Dear Ayush, 'o_ref' is just an object i used there. The name of the database is 'StudentDetails' not the 'o_ref'. 'o_ref' is just an object and you can create as many as objects you want of the same class. So No need to confuse here, just try to understand that the name of the DB is what we give the name of class in 'models.py' and in the 'views.py', we just used that class by creating an object of that class.
Please go through below links and let me know if you will not get anything :-




otJB
Автор

Getting null after inserting values why

swaroopkv
Автор

Yo man, there is a problem when I am doing it when I go to /new/ it automatically makes a dummy object and stores it into the database without pressing the save button. The id = None and all the values are null, what should I do to solve this issue?

Alexander-revz
Автор

Bro plz tell me o_ref object you used but where is it store in database because database table name is different and o_ref is different so how it is automatically store plzz tell me solution as soon as possible????

AyushKumar-kzor
Автор

please give me solution for this error
NOT NULL constraint failed:

ramakrishnaanagandla
Автор

where is the html files in your github?

tayyabarasheedahmad