Please pass the form to the template :)
On Wed, May 14, 2014 at 11:24 AM, G Z <[email protected]> wrote: > Below is my code. I am trying to generate a customer signup form from the >> Customer model in the models.py file. >> > Below I have created forms.py which is the script that will generate the > form data based on what is in the models.py file. > Then in views. I call that forms.py file to run and display the form data. > However no fields are populated just the submit button shows. > > > *forms.py* > > from django import forms > from .models import Customer > > class SignUpForm(forms.ModelForm): > class Meta: > model = Customer > *models.py* > > class Customer(models.Model): > NAME = models.CharField(max_length=200) > WEBSITE = models.CharField(max_length=200) > PHONE = models.CharField(max_length=200) > EMAIL = models.CharField(max_length=200) > ADDRESS = models.CharField(max_length=200) > VMIDS = models.CharField(max_length=200) > > def __unicode__(self): > return self.NAME > > > *views.py* > > from django.shortcuts import render > from django.http import HttpResponse > from vmware.models import Customer > from django.shortcuts import render_to_response > from vmware.models import Vms > from .forms import SignUpForm > > > def index(request): > form = SignUpForm(request.POST or None) > if form.is_valid(): > save_it = form.save(commit=False) > save_it.save() > customers = Customer.objects.all() > ctx = { 'customers':customers } > return render_to_response('index.html', ctx) > > > *index.html* > > <form action='' method='POST'> {% csrf_token %} > {{ form.as_p }} > <p><input type="submit" value="Add"></p> > </form> > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/ec521775-9a04-4989-802a-882f90d65a88%40googlegroups.com<https://groups.google.com/d/msgid/django-users/ec521775-9a04-4989-802a-882f90d65a88%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN7tdFT%3D05cwd2g5%3Dc0-BgstLxAkp%3DefbbuyX5yuPWseiv-y0Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

