-1
我想寫一個簡單的應用程序,讓用戶在Django中登錄。我已經下載了一個漂亮的bootstrap登錄模板,但是我無法將它連接到我的Django項目。當我點擊提交,沒有任何反應,這裏的觀點:從表單中獲取數據到Django無法正常工作
def login_view2(request):
if request.method == 'POST':
print("POST METHOD")
form = LoginForm(request.POST)
if form.is_valid():
print("FORM VALID")
uname = form.cleaned_data['username']
pword = form.cleaned_data['password']
user = authenticate(username=uname, password=pword)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect('/')
else:
print("The account has been disabled!")
else:
print("The username and password were incorrect!")
else:
print("LOGIN FORM SHOWN")
form = LoginForm()
return render(request, 'login2.html', {'form': form})
和這裏的形式
<form id="login-form" action="login2/" method="post">
{% csrf_token %}
<div class="modal-body">
<div id="div-login-msg">
<div id="icon-login-msg" class="glyphicon glyphicon-chevron-right"></div>
<span id="text-login-msg">Type your username and password.</span>
</div>
<input id="login_username" class="form-control" type="text" placeholder="Username" required>
<input id="login_password" class="form-control" type="password" placeholder="Password" required>
</div>
<div class="modal-footer">
<div>
<input type="submit">Login</input>
</div>
</div>
</form>
非常感謝你提前!
不,這不是你如何提出問題。您在問題本身中發佈代碼的*相關部分。 –
@DanielRoseman你說得對,對不起。我剛剛編輯了這個問題。 – Blademaster