码迷,mamicode.com
首页 > 其他好文 > 详细

requests请求例子

时间:2019-03-19 10:28:43      阅读:178      评论:0      收藏:0      [点我收藏+]

标签: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())

 

requests请求例子

标签:params   class   param   add   infer   pass   sts   arm   view   

原文地址:https://www.cnblogs.com/huagongzi/p/10556750.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!