What does the Django "expected string or buffer" error indicate?

Andrew picture Andrew · Nov 29, 2010 · Viewed 19.2k times · Source

I've been stuck with this error for quite a while now and I just can't figure out what it means. It occurs when I try to save an object to my mysql database. Any ideas?

Thanks for the help!

Answer

Michael Pollmeier picture Michael Pollmeier · Jul 4, 2011

Just ran into the same problem and resolved it. I instantiated a form like this:

data = {'date' : datetime.now} #this is the problem
form = MyForm(data)

That form was saved later on and django tried to set 'date' in the model. But datetime.now refers to a function rather than a date, obviously. What I wanted to do was datetime.now()

Maybe this helps anybody running into this in future.