2

First a bit of an introduction. I will send a POST to a url and it will have either ip, mac or hostname. Now depending on which of these key' are in the QueryDict i want it to do certain calls. I.e:

Output of

print request.POST

<QueryDict: {u'ip': [u'10.1.24.178'], u'message': [u'Test'], u'client': [u'auabrthin1']}>

I want to write something like this:

if request.POST['client'] in request.POST:
    do_something()

however request.POST['client'] obviously is the value of client how can I check if a request.POST has a key?

1 Answer 1

8
if 'client' in request.POST:
    # do something
Sign up to request clarification or add additional context in comments.

4 Comments

Yeah, just saw it in [Django docu][docs.djangoproject.com/en/dev/ref/request-response/…, Thanks anyway @ThiefMaster
Yep... the request.POST is just a standard dict.
@jro: request.POST behaves in many cases like a standard dict, but is in fact a QueryDict. It can, for example, have multiple values for the same key.
@lazerscience: indeed, which is what I meant, but I see now that I worded it incorrectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.