MultiValueDictKey 오류가 발생합니다. 로그인 시도 후 MultiValueDictKeyError
이
내이다 :from django.shortcuts import render
from django.contrib.auth import authenticate, login
from django.http import HttpResponse, HttpResponseRedirect
from bookonshelf import settings
def Login(request):
next = request.GET.get('next', '/home/')
if request.method == "POST":
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect(next)
else:
return HttpResponse("Inactive user.")
else:
return HttpResponseRedirect(settings.LOGIN_URL)
return render(request, "index/login.html", {'redirect_to': next})
그리고 내 login.html : 이미 온라인 몇 가지 비슷한 문제를 읽은 후 request.POST.get하는 request.POST를 변경 시도
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Admin panel</title>
<!-- Bootstrap core CSS -->
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="/static/css/ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="/static/css/signin.css" rel="stylesheet">
<!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
<!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file- warning.js"></script><![endif]-->
<script src="/static/assets/js/ie-emulation-modes-warning.js"></script>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"> </script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<form class="form-signin" method="post" action=".?next={{ redirect_to }}"> {% csrf_token %}
<h2 class="form-signin-heading">Admin panel</h2>
<label for="username" class="sr-only">Username</label>
<input type="text" id="username" class="form-control" placeholder="Username" required autofocus>
<label for="password" class="sr-only">Password</label>
<input type="password" id="password" class="form-control" placeholder="Password" required>
<div class="checkbox">
<label>
<input type="checkbox" value="remember-me"> Remember me
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div> <!-- /container -->
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<script src="/static/js/ie10-viewport-bug-workaround.js"></script>
</body>
</html>
하지만, 그건 나를 위해 작동하지 않습니다.
def Login(request):
next = request.GET.get('next', '/home/')
if request.method == "POST":
username = request.POST.get('username', False)
password = request.POST.get('password', False)
user = authenticate(username=username, password=password)
어떻게 해결할 수 있습니까?
귀하의 login.html – itzMEonTV
및 .get으로 변경했을 때 사용한 코드를 게시하십시오. 또한 이런 종류의 시나리오를 다루는 데 특별히 필요한 장고 (Django) 양식을 사용하지 않는 이유를 설명하십시오. –
가능한 [django MultiValueDictKeyError 오류의 중복, 어떻게 처리합니까] (http://stackoverflow.com/questions/5895588/django-multivaluedictkeyerror-error-how-do-i-deal-with-it) – Sayse