我想在 Django 中创建一个登录表单,我使用了这个方法:
def Login(request):
if request.method == 'POST':
form = AuthenticationForm(request.POST)
if form.is_valid:
username = request.POST['username']
password = request.POST['password']
access = authenticate(username=username, password=password)
if access is not None:
if access.is_active:
login(request,access)
return HttpResponseRedirect('/')
else:
return render_to_response('noactive.html', context_instance=RequestContext(request))
else:
HttpResponseRedirect('/')
else:
form = AuthenticationForm()
return render_to_response('login.html', {'form':form}, context_instance=RequestContext(request))
有没有办法使用在 forms.py 中创建的表单而不是 Django 提供给您的 django.contrib.auth.forms.AuthenticationForm 创建表单?