Django的中间件使得POST请求空白 [英] django middleware making post request blank

查看:481
本文介绍了Django的中间件使得POST请求空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我发送POST数据捕获为空白,如果我使用的中间件。我究竟做错了。

The post data that i am sending is captured as blank if i am using middleware, if i remove the middleware from settings.py file it returns the post data. what am i doing wrong.

在这里输入的形象描述

下面是当我删除中间件正确的结果

在这里输入的形象描述

这是中间件code:压痕可能是错在这里。

This is the middle ware code: indentation might be wrong here

class CheckAuthorization(object):
def process_request(self, request):
    getKey = request.POST.get('authKey')
    token = request.POST.get('token')
    full_path = request.get_full_path()
    if getKey is not None and getKey != '' and full_path != "/users/splash/":
        try:
            auth = TblAutherization.objects.get(secret_key = request.POST.get('authKey'))
        except TblAutherization.DoesNotExist:
            response = JsonResponse({'Status':'Error','Response code': 107,'Message':full_path})
            return HttpResponse(response, content_type='application/json')
    else:
        return None
    if token is not None and token != '' and  'settoken' in request.session and full_path != "/users/splash/":
        try:
            auth = TblLoginAuth.objects.get(token = request.POST.get('token'))
        except TblLoginAuth.DoesNotExist:
            response = JsonResponse({'Status':'Error','Response code': 107,'Message':'Invalid Request'})
            return HttpResponse(response, content_type='application/json')
    else:
        return None 

views.py

def splash(request):
if request.method == 'POST':
    try:
        appId = request.POST.get('appId')
    except: 
        return Response({'Status':appId})

    gcmToken = request.POST.get('gcmToken')
    deviceType = request.POST.get('deviceType')
    userId = request.POST.get('userId')
    loginStatus = request.POST.get('loginStatus')
    appType=request.POST.get('appType')
    return Response({'appId':appId,'gcmToken':gcmToken,'deviceType':deviceType})
else:
    return Response({'appId':appId,'gcmToken':gcmToken,'deviceType':deviceType})

它甚至没有打算在除当我尝试使用除

it's not even going in except when i used try except

推荐答案

我不是在中间件方面的专家,但我知道,我们用它在我们的项目,而我看到的主要区别是,你是不是返回响应在成功的案例。所以,我看你有没有尝试:AUTH =等等,但你不使用它。所以,你总是通过Htt的presponse返回无或错误()。关于成功是什么?

I am not an expert in middleware, but I know we use it in our projects and the key difference that I see is that you aren't returning a response on the successful cases. So I see you have try: auth = blah, but you don't use it. So you are always returning None or an error via HttpResponse(). What about success?

这篇关于Django的中间件使得POST请求空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆