Djoser在端点创建用户上不起作用

时间:2019-08-08 17:46:42

标签: django python-3.x django-rest-framework djoser

我正在尝试使用django-rest-framework在我的项目中实现djorse,但是在尝试创建或删除用户时,由于未配置端点,因此无法正常工作。

我该如何解决?

我已经配置了django设置文件来集成djoser,但仍然无法正常工作。

settings.py

DJOSER = {
    "ACTIVATION_URL": "activate/{uid}/{token}/",
    "PASSWORD_RESET_CONFIRM_URL": urllib.parse.urljoin(
        WEB_APP_URL, "/password/reset/confirm/{uid}/{token}"
    ),
    "EMAIL": {
        "activation": "users.emails.ActivationEmail",
        "confirmation": "djoser.email.ConfirmationEmail",
        "password_reset": "users.emails.PasswordResetEmail",
    },
    "PERMISSIONS": {
        "activation": ["rest_framework.permissions.AllowAny"],
        "password_reset": ["rest_framework.permissions.AllowAny"],
        "password_reset_confirm": ["rest_framework.permissions.AllowAny"],
        "set_password": ["djoser.permissions.CurrentUserOrAdmin"],
        "set_username": ["rest_framework.permissions.IsAuthenticated"],
        "user_create": ["rest_framework.permissions.AllowAny"],
        "user_delete": ["rest_framework.permissions.IsAdminUser"],
        "user": ["djoser.permissions.CurrentUserOrAdminOrReadOnly"],
        "user_list": ["crm.permissions.IsAdminOrCoach"],
        "token_create": ["rest_framework.permissions.AllowAny"],
        "token_destroy": ["rest_framework.permissions.IsAuthenticated"],
    },
    "SEND_ACTIVATION_EMAIL": True,
    "SET_PASSWORD_RETYPE": True,
    "SERIALIZERS": {
        "current_user": "auth.serializers.CurrentUserSerializer",
        "user": "auth.serializers.CurrentUserSerializer",
        "user_create": "users.api.serializers.UserRegistrationSerializer",
    },
}

users / serializers.py

class UserRegistrationSerializer(UserCreateSerializer):
    email = serializers.EmailField(
        max_length=200,
        validators=[
            UniqueValidator(
                queryset=User.objects.all(), message=USER_ALREADY_EXISTS_ERROR_MESSAGE
            )
        ],
    )

    class Meta(UserCreateSerializer.Meta):
        pass

urls.py

urlpatterns += [
    path("crm/", include("crm.urls", namespace="crm")),
    path("workouts/", include("workouts.urls", namespace="workouts")),
    path("api/v1/auth/", include("auth.urls", namespace="auth-api")),
    path("api/v1/accounts/", include("djoser.urls")),
    path(
        "api/v1/accounts/users/activate/<str:uid>/<str:token>/",
        ActivateAccountView.as_view(),
        name="activate-user-account",
    ),
    path(
        "activation-failed",
        ActivateAccountFailed.as_view(),
        name="activate-user-account-failed",
    ),
    path("api/v1/", include("crm.api.urls", namespace="crm-api")),
    path("api/v1/", include("workouts.api.urls", namespace="workouts-api")),
    path("api/v1/documentation/", schema_view.with_ui("swagger", cache_timeout=0)),
]

当我{POST}向端点api / v1 / accounts / users / create请求时,这是错误

{
    "detail": "Method \ "POST \" not allowed."
}

0 个答案:

没有答案