code: def change_username_view(self):
          
  
          # Initialize form
          form = self.ChangeUsernameFormClass(request.form)
  
          # Process valid POST
          if request.method == 'POST' and form.validate():
  
              # Change username
              new_username = form.new_username.data
              current_user.username=new_username
              self.db_manager.save_object(current_user)
              self.db_manager.commit()
  
              # Send username_changed email
              self.email_manager.send_username_changed_email(current_user)
  
              # Send changed_username signal
              signals.user_changed_username.send(current_app._get_current_object(), user=current_user)
  
              # Flash a system message
              flash(_("Your username has been changed to '%(username)s'.", username=new_username), 'success')
  
              # Redirect to 'next' URL
              safe_next_url = self._get_safe_next_url('next', self.USER_AFTER_CHANGE_USERNAME_ENDPOINT)
              return redirect(safe_next_url)
  
          # Render form
          self.prepare_domain_translations()
          return render_template(self.USER_CHANGE_USERNAME_TEMPLATE, form=form)
docs: Prompt for new username and old password and change the user's username.