gpt4 book ai didi

html - 如何在 Django 和 Python Shell 中开始调试 POST 和 GET 请求

转载 作者:行者123 更新时间:2023-11-29 13:34:02 25 4
gpt4 key购买 nike

我写了下面的代码。我遇到的问题是数据库没有更新,也没有创建新记录。我假设我检索 POST 的方式不正确,但这就是为什么我问我从哪里开始调试?我已经为数量、 Action 、构建和测试创建了模板变量。例如,当我尝试在 html {{ test }} 中调用它们时,即使是硬编码的也没有任何显示。我使用了 Firebug ,并且表单确实发布了应该发布的值。该表格由两个下拉菜单组成,一个用于操作,一个用于构建。一个数字输入量,一个文本框和一个提交按钮。如果有人能给我一些建议,我将不胜感激。我真的不明白为什么硬编码的没有出现如果您需要更多信息,请告诉我。

def update(request,Type_slug, slug, id):
error = False
Slug = slug
ID = id
Type = Type_slug
test = 'test'
quantity = request.POST['Qty']
action = request.POST['Action']
building = request.POST['Building']
comments = request.POST['Comments']
if Type == 'Chemicals':
item = Chemicals.objects.filter(S_field=Slug, id= ID)
New_Record = ChemicalRecord(Name=item.Name,Barcode=item.Barcode,Cost=item.Cost,Action=action,Building=building)
if building == 'Marcus':
building_two = 'Pettit'
elif building =='Pettit':
building_two ='Marcus'
Record_one = ChemicalRecord.objects.filter(Barcode=New_Record.Barcode).filter(Building=New_Record.Building)
if Record_one:
Record_one = ChemicalRecord.objects.filter(Barcode=New_Record.Barcode).filter(Building=New_Record.Building).latest('id')
New_Record.On_hand = Record_one.On_hand
else:
New_Record.On_hand = 0
if action == 'Receiving':
New_Record.On_hand = New_Record.On_hand+quantity
elif action == 'Removing':
New_Record.On_hand = New_Record.On_hand-quantity
Record_two = ChemicalRecord.objects.filter(Barcode=New_Record.Barcode).filter(Building=building_two)
if Record_two:
Record_two = ChemicalRecord.objects.filter(Barcode=New_Record.Barcode).filter(Building=building_two).latest('id')
Record_two_qty = Record_two.On_hand
else:
Record_two_qty = 0
New_qty = New_Record.On_hand+Record_two_qty
Chemicals.objects.filter(Barcode=obj.Barcode).update(On_hand=New_qty)
New_Record.save()

最佳答案

您可以使用 import pdb;pdb.set_trace()用于调试。

关于html - 如何在 Django 和 Python Shell 中开始调试 POST 和 GET 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17410797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com