2016-04-23 7 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を

アナスサイード

答えて

1

すべての最初の、ジャンゴ

におけるHTTPリクエストのhere are all available headersので、次のものが必要です。

request.META['CONTENT_TYPE'] 

代わりの

request.meta['CONTENT_TYPE'] 
関連する問題