轴后端请求参数必需django

时间:2019-12-15 03:22:59

标签: django locking axes

我在自定义视图中使用轴,以便在3次失败日志后阻止我的电子商务客户。 每次尝试与任何用户登录时,我都会收到错误消息“需要后端后端请求参数”。 如果从AUTHENTICATION_BACKENDS删除'axes.backends.AxesBackend',错误将消失。  我会很感激任何帮助或建议。 谢谢

Error: AxesBackendRequestParameterRequired at /account/signin/
AxesBackend requires a request as an argument to authenticate

设置

AUTHENTICATION_BACKENDS = [
# AxesBackend should be the first backend in the AUTHENTICATION_
'axes.backends.AxesBackend',
# Django ModelBackend is the default authentication backend.
'django.contrib.auth.backends.ModelBackend',


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'store',
    'stripe',
    'crispy_forms',
    'axes',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',   #clickjacking protection 
    # 'axes.middleware.FailedLoginMiddleware',
    'axes.middleware.AxesMiddleware',


VIEWS


from django.contrib.auth.forms import AuthenticationForm
from django.contrib.auth import login, authenticate, logout
from django.contrib.auth.decorators import login_required
from django.contrib.auth.signals import user_logged_in
from django.contrib.auth.signals import user_logged_out
from axes.decorators import axes_dispatch

@axes_dispatch
def signinView(request):
    if request.method == 'POST':
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username= username, password= password, request=request)
            if user is not None:
                login(request,user)

                return redirect('home')
            else:
                return redirect('signup')


    else:
        form = AuthenticationForm()
    return render(request, 'signin.html', {'form': form})

谢谢

0 个答案:

没有答案