[Answer]-Append new value to old value

1👍

You need to simplify the loop, so that you can debug it correctly. Use get (a method of dictionaries) to fetch the key, and you can assign it a default value if the key doesn’t exist.

Putting this together, your code now is:

def update_profile(data, profile_username):

    profile = Profile.objects.get(username=profile_username) #(WORKING)
    profile.info = u'{}\n{}'.format(profile.info, data.get('info', '').encode('utf-8'))
    profile.save()

Leave a comment