當我增加一個變量時,它只會上升到2而不是3.默認值是1.我不知道我在想什麼。任何幫助表示讚賞。Django Views Incrementing Variables
def unanswered(request, template ='unanswered.html'):
phone_number = Pool.objects.order_by('?')[0]
pool = Pool.objects.order_by('?')[0]
pool_list = Pool.objects.all()
number_attempts = Pool.objects.filter(phone_number=phone_number).count()
# unanswer number action
if pool_list:
if number_attempts > 3:
return number_attempts
else:
x = number_attempts
x += 1
print x 'returns 2'
store = Pool(id=phone_number.id,
phone_number = phone_number.phone_number,
un_answered=x, answered=0)
store.save()
payload = {'pool':pool,}
return render_to_response(template, payload, context_instance=RequestContext(request))
從你的問題,我不能猜測什麼是number_attempts'的''中塊else'的價值。如果它是'1',那麼'x + = 1'確實應該返回'2'。 :-) –
number_attempts,它計算它獲得的確切phone_number的數量。所以默認它是1,然後我想繼續增加,直到它達到3. – Infinixd