requests请求例子

Posted huagongzi

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了requests请求例子相关的知识,希望对你有一定的参考价值。

实例一:

    

 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, [email protected]#123))
 9     #ret = requests.get(url=url,params=parm, auth=(‘jiayou3‘, ‘[email protected]#123‘))
10     print(ret.json())

 

以上是关于requests请求例子的主要内容,如果未能解决你的问题,请参考以下文章

requests请求例子

request.getParameter讲解

request.getParameter讲解

小程序跳转请求带参数请求小例子

golang goroutine例子[golang并发代码片段]

django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)(代码片段