【发布时间】:2018-02-20 05:00:18
【问题描述】:
我正在为用户创建一个基本的登录功能。如果登录成功,我会将用户重定向到我在 HttpResponseRedirect 中硬编码的索引页面。但是一旦我点击登录按钮,它会说,
/Login/ 处的类型错误 login() 接受 1 个位置参数,但给出了 2 个
urls.py 中的索引页面 id 定义如下,
url(r'^$',views.index,name='index'),
下面是我的索引视图和登录视图的代码:
def index(request):
return render(request,'authentication_app/index.html')
def login(request):
if request.method=='POST':
username=request.POST.get('name')
password=request.POST.get('password')
user = authenticate(username=username,password=password)
if user:
if user.is_active:
login(request,user)
return HttpResponseRedirect('/')
else:
return HttpResponse('Your Account has become Invalid')
else:
print('Someone tried to login with wrong credentials:{0},{1}'.format(username,password))
return HttpResponse('Username and Password mismatch.Please enter valid credentials')
else:
return render(request,'authentication_app/login.html',{})
【问题讨论】:
标签: django