Friday, October 24, 2014

Re: View didn't return an HttpResponse object

I have in views.py

message="Password was changed"
return logout_then_login(request, login_url='/login/',extra_context={'message': message})


And I want display this message in

login.html below

{% 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 %}

What I do wrong, this message is not show :/

W dniu wtorek, 7 października 2014 20:37:49 UTC+2 użytkownik Dariusz Mysior napisał:
I have form to change password like below, and when I try to display it I have an bug:

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.

My forms.py is:
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ą")



urls.py

url(r'^password_change/$', views.password_change_dom, name='change_password')

change_password.html

{% 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 %}


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3b8f21b6-ecbb-4912-a45b-f758b73fb5c4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment