2016-04-23 58 views
1

大家好我是新的Python和Django其实也在编码。如何处理与Django HTTP.Request,请求内容类型,查询参数

我想构建一个应用程序,它可以接收Content_Type'application/xml'的POST请求。

我不明白如何处理django中的HTTP.Request.META。 首先我想检查一下Content_type,然后是Query_string,然后是Content_Lenght。

from django.views.decorators.csrf import csrf_exempt 
from django.shortcuts import render 
from django.http import (
HttpResponse, HttpResponseNotAllowed, HttpRequest,) 


@csrf_exempt 
# Check the HTTP Request Method 
def app(request): 
    if request.method != "POST": 
     return HttpResponseNotAllowed(permitted_methods=('POST',)) 
    else: 
     # checkcontent(request) 
    return HttpResponse('OK') 

“““ 
def checkcontent(request): 
    if not 'application/xml' in request.meta['CONTENT_TYPE']: 
     raise Exception("Invalid content-type. The expected request content-type is 'application/xml'") 

“““ 

评论块不起作用!

有人可以解释我吗?

THX

阿纳斯·赛义德

回答