我有一个 django 应用程序,我创建了一个登录用户的函数,但它显示错误
这就是景色
def loginpage(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect('home')
else:
return HttpResponse("Username or Password is incorrect!!!")
return render(request, 'login.html')
def LogoutPage(request):
logout(request)
return redirect('login')
这是html代码
{% load static %}
<!DOCTYPE html>
<html lang="us">
<head>
<meta charset="UTF-8">
<title>Login</title>
<link rel="stylesheet" href="{% static 'css/login.css' %}">
</head>
<body>
<div class="login-form">
<form method="post">
{% csrf_token %}
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Login</button>
</form>
<p>Don't have an account? <a href="{% url 'signup' %}">Sign up here</a></p>
</div>
</body>
</html>
这是网址
path('login/', userview.loginpage, name='loginpage'),
这是显示的错误 /登录/
处出现类型错误login() 缺少 1 个必需的位置参数:'user'
请求方式:GET 请求网址:http://127.0.0.1:8000/login/ Django 版本:4.2.11 异常类型:TypeError 异常值:
login() 缺少 1 个必需的位置参数:'user'
异常位置:C:\Users\kakarot\PycharmProjects\TradingApp.venv\Lib\site-packages\djang