我得到一个TypeError: options() missing 1 required positional argument: 'context'的代码:def post_ad(request):
filename = request.POST.get('temp_s3_url')
boost_form = AdvertisePostForm(request.POST or None, request.FILES or None)
if boost_form.is_valid():
instance = boost_form.save(commit=False)
if Post.objects.filter(hash=instance.hash).exists():
instance.hash = random_string()
instance.ad = True
instance.save()
context = {
'hash': instance.hash,
}
return options(request, context)
context = {
'boost_form': boost_form
}
return render(request, 'advertising/post_ad.html', context)
def options(request, context):
ad = get_object_or_404(AdvertisePost, hash=context['hash'])
if request.is_ajax():
total_price = request.POST.get('total_price')
print('Total price:', total_price)
context = {
'ad': ad
}
return render(request, 'advertising/options.html', context)
js
^{pr2}$
当我删除context作为位置参数,或者将def options(request, context):更改为{}时,它可以工作(没有错误,ajax调用在我的视图中成功打印。{cd2>但是数据必须保存。我怎样才能避开这个问题?在