gpt4 book ai didi

python - 属性错误对象没有属性 cleaned_data

转载 作者:太空宇宙 更新时间:2023-11-03 12:20:39 24 4
gpt4 key购买 nike

我的 views.py 代码:

def update_details(request):
if request.method == "POST":
form = UpdateDetailsForm(request.POST)
if form.is_valid:
asset_code=form.cleaned_data['asset_code1']
fd=form.cleaned_data['product_details']
verifications = Verification.objects.filter(asset_code__exact=asset_code)
verifications.update(product_details=fd)

return render_to_response('update_details.html',
{'form':UpdateDetailsForm(),},
context_instance=RequestContext(request))

我想更新模型中的“product_details”列值,其中 Assets 代码正是用户输入的内容。但是当我提交按钮时出现错误。

错误信息:

AttributeError 对象没有属性 'cleaned_data' django

最佳答案

form.is_valid 是一个方法;你需要调用它:

from django.shortcuts import render, redirect

def update_details(request):
if request.method == "POST":
form = UpdateDetailsForm(request.POST, request.FILES)
if form.is_valid():
asset_code=form.cleaned_data['asset_code1']
fd=form.cleaned_data['product_details']
verifications = Verification.objects.filter(asset_code__exact=asset_code)
# filter returns a list, so the line below will not work
# you need to loop through the result in case there
# are multiple verification objects returned
# verifications.update(product_details=fd)
for v in verifications:
v.update(product_details=fd)

# you need to return something here
return redirect('/')
else:
# Handle the condition where the form isn't valid
return render(request, 'update_details.html', {'form': form})

return render(request, 'update_details.html', {'form':UpdateDetailsForm()})

关于python - 属性错误对象没有属性 cleaned_data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20235386/

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