At a particular url, my view is looking for XML document to be sent
over http, by post. If a request come in without post, I want to
raise an error "405 Method Not Allowed". How do I do this?
Thank you
response = HttpResponse('some output here')
response.status_code = 405
return response
--
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."
In fact 405 doesn't mean "post without data", you should answer 405 if
you receive anything except 'POST' in HTTP method. This is done by a not
very well-known decorator:
from django.views.decorators.http import require_http_methods
@require_http_methods('POST')
def your_view(request):
...
I think your app should react on an empty POST as it does on any invalid
XML document. I mean just get request.raw_post_data and send it to a
parser as you (presumably) do now. It doesn't matter if it has '' or
'some garbage' there.
from django.http import HttpResponseNotAllowed
return HttpResponseNotAllowed()