我有一個登錄表單。每當我第一次登錄時,它會再次詢問我的用戶名和密碼,而不會顯示我的用戶名和密碼。但是當我用相同的用戶名和密碼重新登錄時,它會完全登錄。這怎麼可能?Django登錄表單 - 登錄到儀表板第二次
這裏是我的代碼: -
{% extends "base1.html" %}
{% block header %}
{% endblock %}
{% block content %}
<div class="wrap">
<div class="content-wrap">
<a href="#" class="logo"></a>
<form action ="." method = POST class="form-signin" class="well form-inline">
<h3 class="form-signin-heading"></h3>
{% csrf_token %}
{{ form.as_p }}
<input type = "submit" value = "login" class="btn btn-primary">
</form>
</div>
</div><!--end of wrap-->
{%endblock%}
我的urls.py文件
from django.contrib.auth.views import login, logout
from django.conf.urls import *
urlpatterns = patterns('',
url(r'login', login,kwargs = {'template_name' : 'auth/login.html'}, name = 'xyz_login'),
url(r'logout', logout,kwargs = {'template_name' : 'auth/logout.html'}, name = 'xyz_logout'),
)
settings.py文件
LOGIN_REDIRECT_URL = '/dashboard/'
LOGIN_URL = '/login/'
AUTHENTICATION_BACKENDS = ('modules.data.backend.MyModelBackend',)
backend.py
from django.contrib.auth.backends import ModelBackend
class MyModelBackend(ModelBackend):
def authenticate(self,username=None, password=None):
return super(MyModelBackend,self).authenticate(username=username,password=password)
將需要服務器控制檯輸出爲此,以便我們可以調試正在進行的請求....還必須在所有瀏覽器中嘗試並確保它不是緩存問題? –
是的,這不是緩存問題。已經檢查過。服務器日誌是當我第一次嘗試登錄時。 '[28/Apr/2014 06:49:22]「POST/dashboard/HTTP/1.1」302 0 [28/Apr/2014 06:49:22]「GET/login /?next =/dashboard/HTTP/1.1「200 1536 ' – PythonEnthusiast
第二次 - [28/Apr/2014 06:50:27]」POST/login/dashboard/HTTP/1.1「302 0 [28/Apr/2014 06:50:27 ]「GET/dashboard/HTTP/1.1」200 11292',它被登錄 – PythonEnthusiast