Thank you very much Roland - it is now working as required!
Best regards,
Leslie
Roland van Laar wrote:
> Leslie Maclachlan wrote:
>
>> Hello everyone,
>>
>> I have written a template and view to allow users to change their password.
>> As soon as it hits the if pForm.is_valid, I get an error that there is a
>> required field (username) missing - I don't understand why it is asking
>> for this field, as I have not created it, but am assigning the username
>> in the view. Could someone please explain what I am missing.
>>
>>
>
> Look in the code at: /django/contrib/auth/forms.py and other files in
> that directory
> for information about how django handles it.
>
>
>> Regards,
>> Leslie
>>
>> The View:
>> class PasswordForm(forms.Form):
>> password = forms.CharField(max_length=20, widget=forms.PasswordInput())
>> password2 = forms.CharField(max_length=20, widget=forms.PasswordInput())
>>
>> @login_required
>> def Change_Password(request, next='/'):
>> message = 'Change Password'
>> pForm = PasswordForm()
>>
>> if request.method == 'POST':
>> if request.POST['submit'] == 'Change':
>> postDict = request.POST.copy()
>>
>>
> You are using LoginForm and not PasswordForm here.
>
>> pForm = LoginForm(postDict)
>> if pForm.is_valid():
>>
>>
> No indent after the if statement. This should raise an error.
>
>> uPass1 = request.POST['password']
>> uPass2 = request.POST['password1']
>> if uPass1 == uPass2:
>> user = get_object_or_404(Employee.objects.get(name__exact
>> = request.session['uid']))
>> #user = request.session['uid']
>> print 'User: ' + user
>> user.set_password(uPass1)
>> user.save()
>> return HttpResponseRedirect(next)
>> else:
>> message = 'Passwords dont match'
>> pForm = PasswordForm()
>>
>> return render_to_response('employee/change_password.html', {
>> 'pForm': pForm,
>> 'message': message })
>>
>> The Template:
>> {% extends "base_template.html" %}
>> {% block title %} Update Alert {% endblock %}
>> {% block top_menu %}
>> <a href="/">Home</a>
>> {% endblock %}
>> {% block content %}
>> <table>
>> <tr><th><h3>{{message}}</h3></th></tr>
>> <form action="" method="post">
>> <tr>{{ pForm }}</tr>
>> </table>
>> <input type="submit" name="submit" value="Change" />
>> </form>
>> {% endblock %}
>>
>>
>
> Regards,
>
> Roland van Laar
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---