[Answer]-Django 1.6: MultiValueDictKeyError

1👍

The problem is that there is no variable ‘time’ in the post object.

What I would suggest is:

1) Have a look at what the post object looks like, by printing it out or writing it to a file. (I think you might be using get instead of post.)

2) When you work with user inputted data always expect that it might be different to expected. (A malicious user or a spider may be crawling your site.) Rather use:

time = post.get('time')
if time:
    time = escape()
else:
    # No time value was submitted ....

0👍

As cchristelis says, the error is because you don’t have a time value in your POST data.

Really for this sort of thing you should be using Django’s forms framework. That is the proper tool for validating user input and doing something with it.

Leave a comment