实例一:
class GetSalerInfo(View):
def post(self, request):
userid = request.POST/GET.get('userid',None)
username = request.POST/GET.get('username',None)
ret = [{'error': 'argument is invalid'}] if userid or username:
users = []
try:
if userid:
user = User.objects.get(pk=userid)
else:
user = User.objects.get(username=username)
for role in [u'区域销售经理',u'销售组长',u'销售人员']:
if user.is_role(role):
users = user.list_inferior_user(role)
users.add(user)
break
if users:
for one in users:
info = {
'userid': one.id,
'username': one.username,
'name': one.first_name
}
ret.append(info)
ret.pop(0)
except:
pass
return HttpResponse(json.dumps(ret))
调用方法:
def req_get_post():
url = 'http://127.0.0.1:7000/api/getsalerinfo/'
parm = {
# 'userid':131,
'username':'yejiyao'
}
ret = requests.post(url=url,data=parm, auth=('jiayou3', '!@#123'))
#ret = requests.get(url=url,params=parm, auth=('jiayou3', '!@#123'))
print(ret.json())