簡體   English   中英

我想將數據保存在sqlite數據庫中,我的查詢在網頁中不起作用,但是相同的代碼在Django Shell中運行正常

[英]I want save data in sqlite Database, My Query not working in webpage But same code wroking fine in Django Shell

我試圖通過Views.py添加一些數據,但是它不能正常工作,但是在django shell中可以正常工作。

Django Shell執行

我的代碼:

username = request.POST['username']
bp = request.POST['bp']
bs = request.POST['bs']
height = request.POST['height']
weight = request.POST['weight']
temp = request.POST['temp']
datasaved = PatTest(Patient= Patient.objects.get(username=str(username)), BS=int(bs), BP=int(bp), PatHeight=float(height), PatientWeight=float(weight), BMI=BMICal(height, weight), TEMPA=int(temp))
            print("Test")
datasaved.save()

終於解決了這個問題。 問題是BMI=BMICal(height, weight) 我只是用BMICal(float(height), float(weight))

因為它是Models類中的float Value,所以我在其中提到了

username = request.POST['username']
            bp = request.POST['bp']
            bs = request.POST['bs']
            height = request.POST['height']
            weight = request.POST['weight']
            tempsd = request.POST['temp']
            print(Patient.objects.get(username=str(username)).PatID)
            datasaved = PatTest(Patient= Patient.objects.get(username=str(username)), BS=int(bs), BP=int(bp), PatHeight=float(height), PatientWeight=float(weight), BMI=BMICal(float(height), float(weight)), TEMPA=int(tempsd))
            datasaved.save()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM