我正在实现自定义中间件,它将检查每个请求的令牌身份验证我希望为每个请求运行此命令,并接受一个请求
class CheckAuthorization(object):
def process_request(self, request):
getKey = request.POST.get('authKey')
if getKey is not None and getKey != '':
try:
auth = TblAutherization.objects.get(secret_key = request.POST.get('authKey'))
except TblAutherization.DoesNotExist:
response = JsonResponse({'Status':'Error','Response code': 107,'Message':'Invalid Request'})
return HttpResponse(response, content_type='application/json')
else:
response = JsonResponse({'Status':'Error','Response code': 105,'Message':'Missing Paramters'})
return HttpResponse(response, content_type='application/json')
我不希望为一个特定的请求调用这个中间件,这是怎么可能的。如果你能指导我用其他方法做同样的事。我对Python不熟悉
谢谢
要忽略特定的url,可以在
process_request
的开头添加一个检查,下面是一个示例代码:相关问题 更多 >
编程相关推荐