标签:params class param add infer pass sts arm view
实例一:
1 class GetSalerInfo(View): 2 def post(self, request): 3 userid = request.POST/GET.get(‘userid‘,None) 4 username = request.POST/GET.get(‘username‘,None) 5 ret = [{‘error‘: ‘argument is invalid‘}] 6 7 if userid or username: 8 users = [] 9 try: 10 if userid: 11 user = User.objects.get(pk=userid) 12 else: 13 user = User.objects.get(username=username) 14 for role in [u‘区域销售经理‘,u‘销售组长‘,u‘销售人员‘]: 15 if user.is_role(role): 16 users = user.list_inferior_user(role) 17 users.add(user) 18 break 19 if users: 20 for one in users: 21 info = { 22 ‘userid‘: one.id, 23 ‘username‘: one.username, 24 ‘name‘: one.first_name 25 } 26 ret.append(info) 27 ret.pop(0) 28 except: 29 pass 30 return HttpResponse(json.dumps(ret))
1 调用方法: 2 def req_get_post(): 3 url = ‘http://127.0.0.1:7000/api/getsalerinfo/‘ 4 parm = { 5 # ‘userid‘:131, 6 ‘username‘:‘yejiyao‘ 7 } 8 ret = requests.post(url=url,data=parm, auth=(‘jiayou3‘, ‘!@#123‘)) 9 #ret = requests.get(url=url,params=parm, auth=(‘jiayou3‘, ‘!@#123‘)) 10 print(ret.json())
标签:params class param add infer pass sts arm view
原文地址:https://www.cnblogs.com/huagongzi/p/10556750.html