diff --git a/rest_framework/apps.py b/rest_framework/apps.py index f6013eb7e..9298c4bf5 100644 --- a/rest_framework/apps.py +++ b/rest_framework/apps.py @@ -8,3 +8,4 @@ class RestFrameworkConfig(AppConfig): def ready(self): # Add System checks from .checks import pagination_system_check # NOQA + from .checks import www_authenticate_behavior_setting_check # NOQA diff --git a/rest_framework/checks.py b/rest_framework/checks.py index d5d77bc59..12c75db3c 100644 --- a/rest_framework/checks.py +++ b/rest_framework/checks.py @@ -1,4 +1,4 @@ -from django.core.checks import Tags, Warning, register +from django.core.checks import Tags, Error, Warning, register @register(Tags.compatibility) @@ -19,3 +19,22 @@ def pagination_system_check(app_configs, **kwargs): ) ) return errors + + +@register(Tags.compatibility) +def www_authenticate_behavior_setting_check(app_configs, **kwargs): + errors = [] + # WWW_AUTHENTICATE_BEHAVIOR setting must be 'first' or 'all' + from rest_framework.settings import api_settings + setting = api_settings.WWW_AUTHENTICATE_BEHAVIOR + if setting not in ['first', 'all']: + errors.append( + Error( + "The rest_framework setting WWW_AUTHENTICATE_BEHAVIOR must be either " + f"'first' or 'all' (it is currently set to '{setting}').", + hint="Set WWW_AUTHENTICATE_BEHAVIOR to either 'first' or 'all', " + "or leave it unset (the default value is 'first').", + id="rest_framework.E001", + ) + ) + return errors