我目前正在使用django教程探索探戈,部分登录我有一个问题。点击登录后,POST不会rango / login,而是rango / login / rango / login。任何人都可以帮我解决这个问题,更重要的是向我解释这种行为?
views.py
中的user_login方法def user_login(request):
if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password = password)
if user:
if user.is_active:
login(request, user)
return HttpResponseRedirect(reverse('index'))
else:
return HttpResponse("Your account is disabled")
else:
print ('invalid login details: {0}, {1}'.format(username,password))
return HttpResponse("Invalid login details supplied")
else:
return render(request, 'rango/login.html', {})
url
url(r'^login/$', views.user_login, name = 'login'),
在html文件中的表单
<h1>login into rango</h1> <br />
<form id="login_form" method="post" action="/rango/login/">
{% csrf_token %}
Username: <input type="text" name="username" value="" size="50"/> <br />
Password: <input type="password" name="password" value="" size="50"/> <br />
<input type="submit" value="submit"/>
感谢您的反应!