DJANGO REST + DJOSER /api/auth/users/activation get invalid



我应该创建一个auth get方法,但是/auth/users/activation get error

{
"uid": [
"Invalid user id or user doesn't exist."
]
}

和这个错误

{
"detail": "Stale token for given user."
}

在email中userid字段是字符串,如"MTE", "Mw"…用户激活信号不工作

卓params

DJOSER = {
"LOGIN_FIELD": "email",
"PASSWORD_CHANGED_EMAIL_CONFIRMATION": True,
'PASSWORD_RESET_CONFIRM_URL': 'api/users/users/password/reset/confirm/{uid}/{token}',
'USERNAME_RESET_CONFIRM_URL': 'api/users/users/username/reset/confirm/{uid}/{token}',
'ACTIVATION_URL': 'api/users/users/activate/{uid}/{token}',
'SEND_ACTIVATION_EMAIL': True,
'SERIALIZERS': {
"user_create": "restapi.app.serializers.RegistrationSerializer",
"user": "restapi.app.serializers.UserSerializer",
"current_user": "restapi.app.serializers.UserSerializer"
},
'PERMISSIONS': {
'user_list': ['rest_framework.permissions.AllowAny'],
}
}

restapi/app/serializers.py

from rest_framework import serializers
from restapi.app.models import *
from .docs import *
from django.contrib.auth.models import User
class PioneerProfileSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = PioneerProfile
fields = ["elo", "max_elo", "min_elo"]
class UserSerializer(serializers.HyperlinkedModelSerializer):
description = serializers.CharField(source="profile.description")
pioneer = PioneerProfileSerializer()
class Meta:
model = User
fields = ["id",
"username",
"first_name",
"last_name",
"description",
"email",
"date_joined",
"pioneer"]
class RegistrationSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ["email", "username", "first_name", "last_name", "email", "password"]
def validate_username(self, value):
check_query = Genre.objects.filter(name=value)
if self.instance:
check_query = check_query.exclude(pk=self.instance.pk)
if self.parent is not None and self.parent.instance is not None:
genre = getattr(self.parent.instance, self.field_name)
check_query = check_query.exclude(pk=genre.pk)
if check_query.exists():
raise serializers.ValidationError('A Genre with this name already exists.')
return value

restapi/app/signal.py

from django.dispatch import receiver
from djoser.signals import user_activated
from .models import Profile
from .models import PioneerProfile
@receiver(user_activated)
def activate_profile(user, request):
Profile.objects.create(user=user)
PioneerProfile.objects.create(user=user)

restapi/app.py

from django.apps import AppConfig

class AccountsConfig(AppConfig):
name = 'accounts'
def ready(self):
import restapi.app.signal

已创建用户权限

PioneerProfile和Profile为空

问题解决。用is_active=True, pre_save信号创建标准的Django用户解决了这个问题

相关内容

  • 没有找到相关文章

最新更新