I am probably staring it right in the face here. But does Django have a way of actually checking what the HTTP Status code is. I'm basically interested if it's the 302 redirect status code. But no matter what I try and search for I'm only getting HTTPResponse() which is no good to me.
1 Answer
Your question unfortunately doesn't make any sense. The reason why you don't get any Google results for this is that there's simply no such thing as a status code for a request. The status code is what the server sends back to the client as a result of the request: it's unavoidably part of the response, not the request.
I suspect however that this is an XY problem. What, exactly, are you trying to achieve? If you need some data to be preserved through a redirect, then you probably want to store it in the session.
2 Comments
Llanilek
I'm trying to check in the view if the view has been accessed directly or as a redirect, as we only wish the view to be access if it's been redirected to.
Daniel Roseman
As I say, then, you should store something in the session in the originating view, then check it in the new view: if it's there, you can be sure it's a redirect.
request.META.get('HTTP_REFERER', None)to see where it was referred from (if anywhere).