ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
* 新建`serializers` 新建文件`/api/serializers.py` ```python from rest_framework import serializers from .models import * class PageRolesSerializer(serializers.ModelSerializer): class Meta: model = PageRoles fields = "__all__" class UserProfileSerializer(serializers.ModelSerializer): password = serializers.CharField(write_only=True) class Meta: model = UserProfile fields = "__all__" def create(self, validated_data): user = super().create(validated_data) user.set_password(validated_data['password']) user.save() return user def update(self, instance, validated_data): user = super().update(instance, validated_data) try: user.set_password(validated_data['password']) user.save() except KeyError: pass return user ```