[英]How can I make an HTTP request with no Content-Type header using django.test.Client?
[英]How to handle with Django HTTP.Request, request content-type, query parameters
大家好,我是 Python 新手,Django 實際上也在編碼領域。
我想構建一個應用程序,它可以接收帶有 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'")
“““
評論區不起作用!
有人可以解釋我嗎?
謝謝
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.