Thursday, September 29, 2016

Re: Django not saving form in DB from frontend

Appologies. In my view after else clause its ContactForm.

On Thu, Sep 29, 2016 at 11:52 AM, Ali khan <> wrote:

I am newbie so I must be doing some stupid mistake here.

I am trying to save a contact form with ModelForm. But its not saving in DB from the frontend form.

class Contact(models.Model):
     name = models.CharField(max_length=100, null=True, blank=True)
     email = models.EmailField()
     send_quote = models.FileField(upload_to='/contacts')

      def __unicode__(self)

from .models import Contact
from djagno import forms
from django.forms import ModelForm

class ContactForm(forms.ModelForm):
        class Meta:
                    model = Contact
                    fields = ['name', 'email', 'send_quote']

from Django.shortcuts import render, redirect
from .forms import ContactForm

def contact_form(request):
        template = 'contact.html'
        if request.method == 'POST':
               form = ContactForm(request.POST or None, request.Files or None)
               if form.is_valid():
                     new_form = form

                return redirect('/')
                  form = RFPForm
            return render(request, template, context={"form":form})


<form action=" " method="POST">
{% csrf_token %}
{{ form }}
<input type='submit' class='btn btn-danger' value='Send' />

Please advise.

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
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment