add buttons to crispy forms

Date: April 18th 2016
Last updated: April 18th 2016

I wanted to add a button on an "update profile page" that would redirect the user to change their password. Go to PasswordChangeFrom to see how the password change form was created. There are several options to do this, including the "onclick" function from JavaScript.

The example I used to create my button came from here:

class SurferForm(forms.ModelForm):
    #<- snipped ->

    def __init__(self, *args, **kwargs):
        super(SurferForm, self).__init__(*args, **kwargs)
        #<- snipped ->
        self.helper = FormHelper()
        self.helper.add_input(Submit('submit', u'Submit'))
        # ============= SOLUTION ===============
        # note that the url pattern for the changepassword page
        # is located at "/changepassword"
                                     "Change password",
                                     onclick="javascript:location.href = \
    class Meta:
        model = Surfer

results matching ""

    No results matching ""