我正在尝试捕获异常但不起作用。这是我认为的代码:
@login_required
def activities_edit(request, edit):
ActivityFormSet = modelformset_factory(Activity, can_delete=True)
act_edit= Activity.objects.filter(campaing=1).get(pk=edit)
try:
if act_edit:
if request.method == 'POST':
formset = ActivityFormSet(request.POST, request.FILES, queryset=Activity.objects.filter(pk=edit))
if formset.is_valid():
formset.save()
return HttpResponseRedirect('/activities/')
else:
formset = ActivityFormSet(queryset=Activity.objects.filter(pk=edit))
except act_edit.DoesNotExist:
return HttpResponseRedirect('/activities/')
我也在尝试:“除了act_edit.DoesNotExist:”但错误仍然存在“活动匹配查询不存在。” 任何的想法?
谢谢!