def get_and_save_vali_code(request): mobile=request.GET.get('mobile',None) if not mobile: message="发生错误"; if not mobile: return 0 print mobile try: vali_code_object=ValidationCode() cur_datetime=datetime.now() vali_code_object.vali_code=str(cur_datetime.microsecond) expire_time= cur_datetime+timedelta(3) vali_code_object.expire_time=expire_time vali_code_object.save() except: return 0 try: # ret_data={} # ret_data["status"] = 200 # ret_data["vali_code"]=vali_code_object.vali_code num=send_short_message(mobile,vali_code_object.vali_code) if num==1: return 1 else: return 0 except: return 0
def get_and_save_vali_code(request): mobile=request.GET.get('mobile',None) if not mobile: message="发生错误,验证码没有发送成功" try: vali_code_object=ValidationCode() cur_datetime=datetime.now() vali_code_object.vali_code=str(cur_datetime.microsecond) expire_time= cur_datetime+timedelta(3) vali_code_object.expire_time=expire_time vali_code_object.is_used=False except: message="发生错误,验证码没有发送成功" try: num=send_short_message(mobile,vali_code_object.vali_code) if num==1: message="验证码发送成功" vali_code_object.save() else: message="发生错误,验证码没有发送成功" except: message="发生错误,验证码没有发送成功" return render_to_response("valicode_status.html",locals(),context_instance=RequestContext(request))