[Answer]-Attribute error- 'QuerySet' object has no attribute

0👍

Queryset is a “list” of objects. You should get the first instance from the queryset using the first() method:

u = user_profile.objects.filter(username=request.session.get('username', '')) \
                        .first()

1👍

You can try this

try:
   u = user_profile.objects.get(username =request.session.get('username', None))
   form = user_profile_form(initial = {'last_name': u.last_name})
   u.delete()
except ObjectDoesNotExist:
   form = user_profile_form()

Leave a comment