MultiValueDictKeyError after trying to log in
<p>I'm getting a MultiValueDictKey error.</p>

<p>This is my view:</p>

<pre><code>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})
</code></pre>

<p>And my login.html:</p>

<pre><code>&lt;!DOCTYPE html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
&lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
&lt;!-- The above 3 meta tags *must* come first in the head; any other head     content must come *after* these tags --&gt;
&lt;meta name="description" content=""&gt;
&lt;meta name="author" content=""&gt;
&lt;link rel="icon" href="../../favicon.ico"&gt;

&lt;title&gt;Admin panel&lt;/title&gt;

&lt;!-- Bootstrap core CSS --&gt;
&lt;link href="/static/css/bootstrap.min.css" rel="stylesheet"&gt;

&lt;!-- IE10 viewport hack for Surface/desktop Windows 8 bug --&gt;
&lt;link href="/static/css/ie10-viewport-bug-workaround.css" rel="stylesheet"&gt;

&lt;!-- Custom styles for this template --&gt;
&lt;link href="/static/css/signin.css" rel="stylesheet"&gt;

&lt;!-- Just for debugging purposes. Don't actually copy these 2 lines! --&gt;
&lt;!--[if lt IE 9]&gt;&lt;script src="../../assets/js/ie8-responsive-file-   warning.js"&gt;&lt;/script&gt;&lt;![endif]--&gt;
&lt;script src="/static/assets/js/ie-emulation-modes-warning.js"&gt;&lt;/script&gt;

&lt;!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media  queries --&gt;
&lt;!--[if lt IE 9]&gt;
  &lt;script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"&gt; &lt;/script&gt;
  &lt;script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"&gt;&lt;/script&gt;
&lt;![endif]--&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;div class="container"&gt;

  &lt;form class="form-signin" method="post" action=".?next={{ redirect_to }}"&gt; {% csrf_token %}
    &lt;h2 class="form-signin-heading"&gt;Admin panel&lt;/h2&gt;
    &lt;label for="username" class="sr-only"&gt;Username&lt;/label&gt;
    &lt;input type="text" id="username" class="form-control" placeholder="Username" required autofocus&gt;
    &lt;label for="password" class="sr-only"&gt;Password&lt;/label&gt;
    &lt;input type="password" id="password" class="form-control" placeholder="Password" required&gt;
    &lt;div class="checkbox"&gt;
      &lt;label&gt;
        &lt;input type="checkbox" value="remember-me"&gt; Remember me
      &lt;/label&gt;
    &lt;/div&gt;
    &lt;button class="btn btn-lg btn-primary btn-block" type="submit"&gt;Sign in&lt;/button&gt;
  &lt;/form&gt;

&lt;/div&gt; &lt;!-- /container --&gt;


&lt;!-- IE10 viewport hack for Surface/desktop Windows 8 bug --&gt;
&lt;script src="/static/js/ie10-viewport-bug-workaround.js"&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>I already tried changing request.POST to request.POST.get after reading some similar problems online, but that's not working for me.</p>

<pre><code>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)
</code></pre>

<p>How do I solve this?</p>

<p>You never give your inputs a name so they are never added to the post data</p>

<pre><code>&lt;input type="text" id="username" name="username"&gt;
&lt;input type="password" id="password" name="password"&gt;
</code></pre>

<p><sub><sub>I removed some attributes for brevity</sub></sub></p>

<p>Also note:</p>

<ul>
<li><p>You should import settings from <code>django.conf</code> (<code>from django.conf import settings</code>), this isn't a module, its a class that does magic to always get the right <code>DJANGO_SETTINGS_MODULE</code>.</p></li>
<li><p>You should just use a django form which can stop these kind of errors from ever occuring</p></li>
<li><p>You should give better defaults than <code>False</code>, these values are strings and False doesn't make sense here.</p></li>
</ul>

python django