ValueError at /password_change/
The view dom.views.password_change_dom didn't return an HttpResponse object.
Request Method: GET Request URL: http://darmys.pythonanywhere.com/password_change/ Django Version: 1.6.5 Exception Type: ValueError Exception Value: The view dom.views.password_change_dom didn't return an HttpResponse object.
class FormularzPasswordChange(forms.Form):
password1 = forms.CharField(label="Hasło:",widget=forms.PasswordInput())
password2 = forms.CharField(label="Powtórz hasło:",widget=forms.PasswordInput())
def clean_password2(self):
password1 = self.cleaned_data['password1']
password2 = self.cleaned_data['password2']
if password1 == password2:
return password2
else:
raise forms.ValidationError("Hasła się różnią")
url(r'^password_change/$', views.password_change_dom, name='change_password')
{% extends "base_site_dom.html" %}
{% block title %} - zmiana hasła {% endblock %}
{% block content %}
<center>
<h2>Zmiana hasła na nowe.</h2>
Wpisz nowe hasło 2 razy.
<p>
<div style="margin-left:35%; margin-right:35%;">
<fieldset>
<form method="post" action=".">{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Zmień"> <input type="reset" value="Wartoci początkowe">
</form>
</fieldset>
</div>
</center>
{% endblock %}
{% block footer %}
<p>
<div style="text-align:center;"><a href="/">Strona głóna</a></div>
</p>
{% endblock %}
ef password_change_dom(request):
if request.method == 'POST':
form = FormularzPasswordChange(request.POST)
if form.is_valid():
user = authenticate(username=form.cleaned_data['username'])
#user = User.objects.get(username='username')
user.set_password(form.cleaned_data['password2']),
user.save()
login(request,user)
template = loader.get_template("registration/change_password.html")
variables = RequestContext(request,{'user':user})
output = template.render(variables)
return HttpResponseRedirect("/")
else:
form = FormularzPasswordChange()
template = loader.get_template('registration/change_password.html')
variables = RequestContext(request,{'form':form})
output = template.render(variables)
return HttpResponse(output)
def password_change_dom(request):
if request.method == 'POST':
form = FormularzPasswordChange(request.POST)
if form.is_valid():
user = authenticate(username=form.cleaned_data['username'])
user.set_password(form.cleaned_data['password2'])
user.save()
login(request, user)
return HttpResponseRedirect("/")
else:
form = FormularzPasswordChange()
return render(request, 'registration/change_password.html', {'form': form})
KeyError at /password_change/
'username'
Request Method: POST
Request URL: http://darmys.pythonanywhere.com/password_change/ Django Version: 1.6.5
Exception Type: KeyError Exception Value: 'username'
Exception Location: /home/darmys/dom/dom/views.py in password_change_dom, line 55
def password_change_dom(request):
if request.method == 'POST':
form = FormularzPasswordChange(request.POST)
if form.is_valid():
request.user.set_password(form.cleaned_data['password2'])
request.user.save()
template = loader.get_template("registration/change_password.html")
variables = RequestContext(request,{'user':request.user})
output = template.render(variables)
return HttpResponseRedirect("/")
else:
form = FormularzPasswordChange()
return render(request, 'registration/change_password.html', {'form': form})
#request.user.set_password(form.cleaned_data['password2'])
#request.user.save()
#return render(request, 'registration/change_password_success.html', {'user': request.user})
from django.contrib.auth import logout,login,authenticate,password_change
.
.
.
password_change(request,'registration/change_password_success.html',post_change_redirect=None,
password_change_form=FormularzPasswordChange, current_app=None, extra_context=None)
#url(r'^password_change/$', views.password_change_dom, name='change_password'),
url(r'^password_change/$', 'django.contrib.auth.views.change_password'),
ImportError at /
cannot import name password_change
Request Method: GET Request URL: http://darmys.pythonanywhere.com/
Django Version: 1.6.5 Exception Type: ImportError Exception Value: cannot import name password_changeException Location: /home/darmys/dom/dom/views.py in <module>, line 7
from django.contrib.auth import logout,login,authenticate,password_change
from django.contrib.auth import logout,login,authenticate
from django.contrib.auth.views import change_password
message="Password was changed"
return logout_then_login(request, login_url='/login/',extra_context={'message': message})
{% extends "base_site_dom.html" %}
{% block title %} - logowanie {% endblock %}
{% block content %}
<center>
<h2> Logowanie na stronie Managera Piłkarskiego GoalKick </>
<p>
<p>{{ message}}</p>
<div style="margin-left:35%;margin-right:35%;">
<fieldset>
<form method="post" action=".">{% csrf_token %}
<div style="text-align:left";>{{ form.as_p }}</div>
<input type="hidden" name="next" value="/" />
<input type="submit" value="Logowanie"/><input type="reset" value="Wartości domyślne" />
</form>
</fieldset>
</div>
</center>
{% endblock %}
{% block footer %}
<p>
<div style="text-align:center;"><a href="/">Strona główna</a></div>
</p>
{% endblock %}
from django.contrib import messages
messages.add_message(request, messages.INFO, 'Password was changed')
return logout_then_login(request, login_url='/login/')
<h2> Logowanie na stronie Managera Piłkarskiego GoalKick </>
<p>
{% for message in messages %}
<p>{{ message }}</p>
{% endfor %}