1

我是 djoser 的新手,在学习教程时,我尝试使用以下命令注册新用户:

curl -X POST http://127.0.0.1:8000/api/users/ --data 'username=example%26password=mysecret'

(我%26在 url 中使用是因为&给出了错误。)

但不幸的是,我得到的输出为:

{"username":["This field is required."],"password":["This field is required."]}

代替:

{"email":"","username":"example","id":1}

我的urls.py文件

urlpatterns = [
    path('admin/', admin.site.urls),
    re_path(r'^api/', include('djoser.urls'))
]

我的settings.py文件

REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    # or allow read-only access for unauthenticated users.
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework_simplejwt.authentication.JWTAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.TokenAuthentication',
        'rest_framework.authentication.BasicAuthentication',
    ],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly',

    ]
}

我将其执行为:

在一个终端中,我正在运行 sqlite 服务器,在另一个终端中,我运行上述命令。

我怀疑这是否是正确的方法。

4

1 回答 1

0

卷曲应该是

curl -X POST 'http://127.0.0.1:8000/api/users/?username=example&password=mysecret'
于 2019-09-09T15:12:32.883 回答