updating user profile using django rest framework api
<p>I want to create an API where user can update their profile. In my case, a user can update his/her username and password. To change his/her profile, an API link should be <code>/api/change/usernameOfThatUser</code>. When I use a non-existing username in the link, I still get the userProfileChange API page, and the input boxes are not filled with previous data. How can I solve this?</p>

<p><strong>serializers.py</strong></p>

<pre><code>User = get_user_model()

class UserProfileChangeSerializer(ModelSerializer):
    username = CharField(required=False, allow_blank=True, initial="current username")
    class Meta:
        model = User
        fields = [
            'username',
            'password',
        ]

    def update(self, instance, validated_data):
        instance.username = validated_data.get('username',instance.username)
        print('instance of username',instance.username)
        return instance 
</code></pre>

<p><strong>views.py</strong></p>

<pre><code>class UserProfileChangeAPIView(UpdateAPIView):
    serializer_class = UserProfileChangeSerializer
    lookup_field = 'username'
</code></pre>

<p><strong>urls.py</strong></p>

<pre><code>  url(r'^change/(?P&lt;username&gt;[\w-]+)$', UserProfileChangeAPIView.as_view(), name='changeProfile'),
</code></pre>