Hallo alles, ich bin neu in Python und Django eigentlich auch in Coding.Wie mit Django HTTP.Request umgehen, Anfrage Inhaltstyp, Abfrage Parameter
Ich möchte eine App erstellen, die eine POST-Anfrage mit dem Content_Type 'application/xml' erhalten kann.
Ich verstehe nicht, wie mit der HTTP.Request.META in Django umzugehen. Zuerst möchte ich den Content_type, dann die Query_string, dann Content_Length überprüfen.
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'")
“““
Der Kommentarblock funktioniert nicht!
Kann mir jemand erklären?
Thx
Anas Syed