returns url of profile image of a user

def img_url(obj, profile_app_name, profile_model_name):
    """ returns url of profile image of a user """
    try:
        content_type = ContentType.objects.get(
            app_label=profile_app_name,
            model=profile_model_name.lower()
        )
    except ContentType.DoesNotExist:
        return ""
    except AttributeError:
        return ""

    Profile = content_type.model_class()
    fields = Profile._meta.get_fields()
    profile = content_type.model_class().objects.get(user=obj.user)
    for field in fields:
        if hasattr(field, "upload_to"):
            return field.value_from_object(profile).url