Home>

Customized login authentication with Django.
When I tried to get the login user after logging in, it became Anonymoususer,
Unable to get login user.
I would like to know the cause.

self.request.user becomes Anonymoususer
Applicable source code
class AccountAuthBackend(ModelBackend):
    def authenticate(self, request, screen_id=None, password=None, **kwargs):
        try:
            user = User.objects.get(screen_id=screen_id)
        except User.DoesNotExist:
            return None
        if user.check_password(password) and self.user_can_authenticate(user):
            return user
        else:
            return None
What I tried

Add the following line to settings.py
SESSION_ENGINE ='django.conrtib.sessions.backends.cache'

Adding the above line causes the following error

Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/local/lib64/python3.6/site-packages/django/core/servers/basehttp.py", line 45, in get_internal_wsgi_application
    return import_string(app_path)
  File "/usr/local/lib64/python3.6/site-packages/django/utils/module_loading.py", line 17, in import_string
    module = import_module(module_path)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:],package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/var/www/html/wto_web_app/wto_web_app/wsgi.py", line 18, in<module>  application = get_wsgi_application()
  File "/usr/local/lib64/python3.6/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
    return WSGIHandler()
  File "/usr/local/lib64/python3.6/site-packages/django/core/handlers/wsgi.py", line 127, in __init__
    self.load_middleware()
  File "/usr/local/lib64/python3.6/site-packages/django/core/handlers/base.py", line 37, in load_middleware
    mw_instance = middleware(handler)
  File "/usr/local/lib64/python3.6/site-packages/django/contrib/sessions/middleware.py", line 15, in __init__
    engine = import_module(settings.SESSION_ENGINE)
  File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:],

 package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_loadFile "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
ModuleNotFoundError: No module named'django.conrtib'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/lib64/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib64/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib64/python3.6/site-packages/django/utils/autoreload.py", line 53, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib64/python3.6/site-packages/django/core/management/commands/runserver.py", line 137, in inner_run
    handler = self.get_handler(*args, **options)
  File "/usr/local/lib64/python3.6/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
    handler = super().get_handler(*args, **options)
  File "/usr/local/lib64/python3.6/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
    return get_internal_wsgi_application()
  File "/usr/local/lib64/python3.6/site-packages/django/core/servers/basehttp.py", line 50, in get_internal_wsgi_application
    ) from err
django.core.exceptions.ImproperlyConfigured: WSGI application'wto_web_app.wsgi.application' could not be loaded;Error importing module.


wsgi is defined as follows
WSGI_APPLICATION ='hogehoge_app.wsgi.application'

Supplemental information (FW/tool ​​version, etc.)

Python3.6.8
Django3.0.8
CentOS8.2.2004

_