私はlogin_requiredデコレータを無効にしてlogin_stateを確認することをお勧めします。 login_stateが真の場合、通常は他のユーザーのセッションをログアウトし、ログインページにリダイレクトします。
以下のコードに従ってください。私はlogin_requiredの動作をカスタマイズするために私のプロジェクトを使用しました。
def custom_user_passes_test(test_func, login_url=None,
redirect_field_name=REDIRECT_FIELD_NAME):
"""
Decorator for views that checks that the user passes the given test,
redirecting to the log-in page if necessary. The test should be a callable
that takes the user object and returns True if the user passes.
"""
def decorator(view_func):
@wraps(view_func, assigned=available_attrs(view_func))
def _wrapped_view(request, *args, **kwargs):
if test_func(request.user):
#get current login_state and store in variable named login_state
if login_state:
return view_func(request, *args, **kwargs)
else:
return redirect_to_login(path, resolved_login_url,
redirect_field_name)
return _wrapped_view
return decorator
def login_required(function=None, redirect_field_name=REDIRECT_FIELD_NAME,
login_url=None):
"""
Decorator for views that checks that the user is logged in, redirecting
to the log-in page if necessary.
"""
actual_decorator = custom_user_passes_test(lambda u: u.is_authenticated(),
login_url=login_url,
redirect_field_name=\
redirect_field_name)
if function:
return actual_decorator(function)
return actual_decorator
確かにこれはあなたがに行く次のページから、ユーザーは、私はDjangoの認証アプリケーションは、ユーザーがログアウトされた場合にログインページにリダイレクトするために、同じlogin_requiredメソッドの定義を使用して推測間違ったログイン状態 – Sayse