The DRF Docs say that once an exception handler is set up, it needs to be defined in the settings.py as follows:
REST_FRAMEWORK = {
'EXCEPTION_HANDLER': 'my_project.my_app.utils.custom_exception_handler'
}
My Django project layout is like this:
backend
settings.py
connectivity_service
utils
Custom404ErrorMessage.py
The project is called backend and the app name is connectivity_service.The Custom404ErrorMessage.py file contains the function custom_exception_handler which handles the exception.
My settings.py looks like this:
REST_FRAMEWORK = {
'EXCEPTION_HANDLER': 'backend.connectivity_service.utils.Custom404ErrorMessage'
}
However, this gives me the following error message:
ImportError: Could not import 'backend.connectivity_service.utils.Custom404ErrorMessage'
for API setting 'EXCEPTION_HANDLER'. ModuleNotFoundError: No module named
'backend.connectivity_service'.
What am i doing wrong ?