【发布时间】:2016-08-17 06:35:57
【问题描述】:
大家好,我是 Python 和 Django 的新手,实际上也是 Coding。
我想构建一个应用程序,它可以接收带有 Content_Type 'application/xml' 的 POST-Request。
我不明白如何在 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'")
“““
评论区不起作用!
谁能解释一下?
谢谢
【问题讨论】:
标签: python django http content-type