我想在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))
有没有办法用在创建的窗体创建窗体表单.py而不是django.contrib.auth公司.forms.AuthenticationFormDjango提供给你的?在
所以,我认为你混淆了两个不同的问题:一个是你想问用户什么。第二个问题是要在数据库中存储什么。在
第一个问题在views和forms中实现,而后一个问题在models,特别是{a4}中实现。在
通常,表单与要对数据库执行的操作相关联。插入新内容或修改现有内容(包括用户登录)。在
所以,我对你的问题的回答是:你应该试着阅读我添加的这4个链接。您必须理解以下基本思想:视图是服务器对用户请求的响应,表单是用用户输入修改数据库而不破坏数据库的工具,模型是以结构化方式存储信息的数据结构。在
希望这有帮助。在
相关问题 更多 >
编程相关推荐