modelform not loading from template

6 views
Skip to first unread message

sum abiut

unread,
Feb 9, 2018, 1:03:58 AM2/9/18
to django...@googlegroups.com
Hi,
i have a hard time figuring out why this form in not loaded on the template. There is no error but the form is not loading. Please advise what i am missing here.

view.py

def addcontact(request):
    if request.method=='POST':
        form =ContactForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponse('Success')
    else:
        form =ContactForm()
    return render(request,'addcontact.html',{'form':form})

form.py

class ContactForm(forms.ModelForm):
    class Meta:
        model =contacts
        fields = ('First_Name', 'Last_Name', 'Department','Extension')


addcontact.html

<form method="post" action="">
  {% csrf_token %}
 
  {{ form }}
  <button type="submit">Submit</button>
</form>





Reply all
Reply to author
Forward
0 new messages