Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Django 版本 3.0.3
我正在尝试使用 Django 的内置用户身份验证系统,特别是它的登录表单和视图。
form = LoginForm()或form = AuthenticationForm()线路在哪里?
form = LoginForm()
form = AuthenticationForm()
我在 LoginView 和 AuthenticationForm 定义中找不到它。而且我对在哪里进行调查没有其他想法。
我只是好奇 Django 如何确定幕后的上下文。
您需要导入内置的身份验证表单
从 django.contrib.auth.forms 导入 AuthenticationForm
您需要为身份验证表单创建一个对象并将其传递给渲染函数。
return render(request, 'user/login.html', {'form': form, 'title': 'Sign In'})
注意: 如果不发送表单实例来呈现功能,登录表单也不会显示与 RegistrationForm 类似。