Answer the question
In order to leave comments, you need to log in
Why are two exceptions thrown?
There is code in the view. If there is no such element in the model (in the database), then a standard exception should be thrown.
Entry.objects.get(id=-999) # raises Entry.DoesNotExist
type object 'Coupon' has no attribute 'DoesNotExists'
@require_POST
def coupon_apply(request):
now = timezone.now()
form = CouponApplyForm(request.POST)
if form.is_valid():
code = form.cleaned_data['code']
try:
coupon = Coupon.objects.get(code__iexact=code,
valid_from__lte=now,
valid_to__gte=now,
active=True)
request.session['coupon_id'] = coupon.id
except Coupon.DoesNotExists:
request.session['coupon_id'] = None
return redirect('cart:cart_detail')
Answer the question
In order to leave comments, you need to log in
Prompted. Typo :
DoesNotExist
DoesNotExists
Question closed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question