[Answer]-Django error, coercing to Unicode: need string or buffer, datetime.timedelta found

1👍

✅

Id suggest you include full listing of function call.

Seems that you try concatenating unicode and datatime object, that is not possible. You have to convert date_arrive to datetime or “datetime.timedelta(days=request.session.get(‘nights’)” to unicode evidently, depending on type your function needs as date_depart argument.

0👍

You should be able to solve this problem by making sure non-unicode/non-strings like integers and datetime objects are surrounded with a str(your_date_object_here).

When I encountered this error in Django I was able to fix it with both the following:

def __str__(self): 
    return str(self.datetimeobject) + " other string return info"

and

def __str__(self):
    return unicode(self.datetimeobject) + " other string return info" 

Leave a comment