Form data is storing in database when using jQuery
<p>i was trying to use jquery to load form when value of drop down change .it loading the form but after submitting data is not storing in database . it just refreshes the page.</p>

<blockquote>
  <p>forms.py</p>
</blockquote>

<pre><code>class accountForm(forms.ModelForm):
    choice = (
        ('payment type','payment type'),
        ('paypal', 'paypal'),
        ('payeer', 'payeer'),
        ('payza', 'payza'),
        ('bitcoin', 'bitcoin'),
        )
    payment_type = forms.ChoiceField(choices = choice, widget = forms.Select(attrs = {'class':'forms-control'}))
    email = forms.EmailField(widget = forms.EmailInput(attrs={'class':'form-control'}))
    bitcoin = forms.CharField(widget = forms.TextInput(attrs = {'class':'form-control'}))
    amount = forms.IntegerField(widget = forms.NumberInput(attrs = {'class':'form-control'}))

    class Meta:
        model = payments
        fields = [
            "payment_type",
            "email",
            "bitcoin",
            "amount",

        ]
</code></pre>

<blockquote>
  <p>views.py</p>
</blockquote>

<pre><code>def payment(request, username):
    form = accountForm(request.POST or None)
    if form.is_valid():
        print(form)
        form.save(commit = False)
        form.save()
        return HttpResponseRedirect('/accounts/profile/')
    context = {'form':form}
    return render(request, 'payment.html', context)
</code></pre>

<blockquote>
  <p>payment.html</p>
</blockquote>

<pre><code>&lt;div class="panel-body"&gt;
                      &lt;div class="tab-content"&gt;
                        &lt;div class="tab-pane active" id="home"&gt;
                          &lt;div class="panel-body" id="panel"&gt;
                            &lt;div class="form-group"&gt;
                              &lt;h4 class="text-primary"&gt;Select Withdrawal Type&lt;/h4&gt;
                              {{ form.payment_type }}
                            &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="panel-body"&gt;
                            &lt;form  method="POST" id="form" enctype='multipart/form-data'&gt;
                            {% csrf_token %}

                            &lt;/form&gt;
                          &lt;/div&gt;
                        &lt;/div&gt;
                      &lt;/div&gt;
                    &lt;/div&gt;
</code></pre>

<blockquote>
  <p>jquery</p>
</blockquote>

<pre><code>&lt;script type="text/javascript"&gt;
  $('select').on('change', function (e) {
    var Selected = $("option:selected", this);
    var valueSelected = this.value;
    console.log(valueSelected);
    if (valueSelected == 'paypal') {
      $("#panel").change(function (e) {
            $("#panel").empty();
            // $('#form').append('{% csrf_token %}');
            $('#form').append('&lt;label&gt;email&lt;/label&gt;');
            $('#form').append('{{ form.email }}');
            $('#form').append('{{ form.amount }}');
            $('#form').append('&lt;button class="btn btn-primary btn-default"&gt;submit&lt;/button&gt;');

        })
    }
  });
&lt;/script&gt;
</code></pre>

<p>Where is the implementation for your forms.save()? Describe how save() is implemented in forms model. It could be somewhere there or If you are using any service like Amazon AWS and botto as interface, the issue could be in these two places also.</p>

<p>Obviously you have only printed the form and you are using HttpResponseRedirect which is why your form is printed and your profile page is reloaded.</p>

jquery python django django-forms django-views