前提・実現したいこと
Djangoでログイン認証をカスタマイズいたしました。
ログイン後にログインユーザを取得しようとしたところ、Anonymoususerとなり、
ログインユーザを取得できません。
原因を教えていただきたいです。
発生している問題・エラーメッセージ
self.request.userがAnonymoususerとなる
該当のソースコード
backends.py
1class AccountAuthBackend(ModelBackend): 2 def authenticate(self, request, screen_id=None, password=None, **kwargs): 3 try: 4 user = User.objects.get(screen_id=screen_id) 5 except User.DoesNotExist: 6 return None 7 if user.check_password(password) and self.user_can_authenticate(user): 8 return user 9 else: 10 return None
### 試したこと
settings.pyに以下行を追加
SESSION_ENGINE = 'django.conrtib.sessions.backends.cache'
上述の行を追加すると以下エラー発生
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_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 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は以下の通り定義
WSGI_APPLICATION = 'hogehoge_app.wsgi.application'
補足情報(FW/ツールのバージョンなど)
Python3.6.8
Django3.0.8
CentOS8.2.2004
_
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。