def index(request):
# jezeli formularz coś wysłał
if request.method == 'POST':
form_r = UserCreationForm(request.POST)
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
# jezeli uzytkownik istnieje
if user is not None:
if user.is_active:
login(request, user)
return HttpResponseRedirect('profile')
else:
# Return a 'disabled account' error message
...
else:
# Return an 'invalid login' error message.
return HttpResponseRedirect('invalid_login')
if form_r.is_valid():
form_r.save()
info="Zarejestrowałeś się!"
return render_to_response('ownsite/register_success.html', {info:'info'})
else:
return HttpResponseRedirect('/')
# tworze formularze
args = {}
args.update(csrf(request))
args['form_l'] = AuthenticationForm()
args['form_r']= UserCreationForm()
return render_to_response('index.html', args)
MultiValueDictKeyError at /
"'password'"
Request Method: POST Request URL: http://127.0.0.1:8000/ Django Version: 1.8.4 Exception Type: MultiValueDictKeyError Exception Value: "'password'"Exception Location: C:\Python34\lib\site-packages\django\utils\datastructures.py in __getitem__, line 322 Python Executable: C:\Python34\python.exe Python Version: 3.4.3 Python Path: ['C:\\Python34\\ownsite', 'C:\\WINDOWS\\SYSTEM32\\python34.zip', 'C:\\Python34\\DLLs', 'C:\\Python34\\lib', 'C:\\Python34', 'C:\\Python34\\lib\\site-packages']Server time: Czw, 17 Gru 2015 22:07:11 +0100
password = request.POST['password']
{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
<title>{% block title %}{% endblock %}</title>
<link rel="stylesheet" type="text/css" href="{% static 'ownsite/css/style.css' %}" />
</head>
<body>
<div id="header">
{% block header %}
{% if user.is_authenticated %}
<p>Jesteś zalogowany <a href='profile'>{{ user.username }}</a></p>
<p><a href='/logout_view'>wyloguj</a></p>
{% else %}
<h2>Login</h2>
<form action = '/' method = 'post'>{% csrf_token %}
{{ form_l.as_p }}
<input type='submit' value='Log' />
</form>
{% endif %}
{% endblock %}
</div>
<div id="content">
{% block content %}
<div id="left_content">
{% block left_content %}
{% if user.is_authenticated %}
<p>Jesteś zalogowany</p>
{% else %}
<p>Zaloguj się lub zarejestruj</p>
{% endif %}
{% endblock %}
</div>
<div id="right_content">
{% block right_content %}
{% if user.is_authenticated %}
<p>Jesteś zalogowany</p>
{% else %}
<h2>Register</h2>
<form action = '/' method = 'post'>{% csrf_token %}
{{form_r.as_p}}
<input type='submit' value='Register' />
</form>
{% endif %}
{% endblock %}
{% endblock %}
</div>
</div>
<div id="footer">
<p>copyright © Dariusz Mysior</p>
</div>
</body>
</html>