英文:
Error "ImproperlyConfigured at /dj-rest-auth/login/" in use "dj_rest_auth"
问题
I Want Use packeage 'dj_rest_auth' in django-rest-framework for login but get error:
ImproperlyConfigured at /dj-rest-auth/login/
No default throttle rate set for 'dj_rest_auth' scope
In setting.py File:
INSTALLED_APPS = [
    ...
    # 3rd Party
    'rest_framework',
    'rest_framework.authtoken',
    'rest_framework_simplejwt',
    'dj_rest_auth',
    # local
    ...
]
REST_USE_JWT = True
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES':[
        'rest_framework_simplejwt.authentication.JWTAuthentication',
        'dj_rest_auth.jwt_auth.JWTCookieAuthentication',
    ],
    'DEFAULT_PERMISSION_CLASSES':[
        'rest_framework.permissions.AllowAny'
    ],
    'DEFAULT_RENDERER_CLASSES':[
        'rest_framework.renderers.JSONRenderer'
    ],
    'DEFAULT_THROTTLE_CLASSES':[
        'rest_framework.throttling.AnonRateThrottle',
        'rest_framework.throttling.UserRateThrottle',
        'rest_framework.throttling.ScopedRateThrottle',
    ],
    'DEFAULT_THROTTLE_RATES':{
        'anon':'50/hour',
        'user':'200/hour',
        'register':'5/hour',
        'ref_token':'5/minute',
        'create_article':'5/minute',
    }
}
And url.py:
urlpatterns = [
    ...
    path('dj-rest-auth/', include('dj_rest_auth.urls')),
]
英文:
I Want Use packeage 'dj_rest_auth' in django-rest-framework for login but get error:
ImproperlyConfigured at /dj-rest-auth/login/
No default throttle rate set for 'dj_rest_auth' scope
In setting.py File:
INSTALLED_APPS = [
    ...
    # 3rd Party
    'rest_framework',
    'rest_framework.authtoken',
    'rest_framework_simplejwt',
    'dj_rest_auth',
    # local
    ...
]
REST_USE_JWT = True
REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES':[
        'rest_framework_simplejwt.authentication.JWTAuthentication',
        'dj_rest_auth.jwt_auth.JWTCookieAuthentication',
    ],
    'DEFAULT_PERMISSION_CLASSES':[
        'rest_framework.permissions.AllowAny'
    ],
    'DEFAULT_RENDERER_CLASSES':[
        'rest_framework.renderers.JSONRenderer'
    ],
    'DEFAULT_THROTTLE_CLASSES':[
        'rest_framework.throttling.AnonRateThrottle',
        'rest_framework.throttling.UserRateThrottle',
        'rest_framework.throttling.ScopedRateThrottle',
    ],
    'DEFAULT_THROTTLE_RATES':{
        'anon':'50/hour',
        'user':'200/hour',
        'register':'5/hour',
        'ref_token':'5/minute',
        'create_article':'5/minute',
    }
}
And url.py:
urlpatterns = [
...
path('dj-rest-auth/',include('dj_rest_auth.urls')),
]
答案1
得分: 0
将以下内容添加到您的settings.py文件中:
'DEFAULT_THROTTLE_RATES': { 
    'dj_rest_auth': '10000/day',
    ...
},
或者在视图中设置throttle_scope为其他值,比如anon。
在项目代码中遇到了相同的问题,并找到了这行代码:
该视图设置了一个自定义的节流范围,在settings.py文件的REST_FRAMEWORK部分中您可能没有配置,因此出现了错误。不清楚为什么他们会进行这种更改并且没有正确记录它。
英文:
TL;DR
Add this into your settings.py file
'DEFAULT_THROTTLE_RATES': { 
    'dj_rest_auth': '10000/day',
    ...
},
or set the throttle_scope within the view to something else like anon.
Experienced the same issue and found this line within the project code
The view sets a custom throttle scope which you would not have configured within the REST_FRAMEWORK section of the settings.py file hence the error. No idea why they would make this change and not document it correctly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论