Hi Dean,


Looks like you pass the class ContractForm in to your render (and not the 
variable contractForm). Also on naming (PEP 8) contract_form would have been 
nicer for the variable (and would have stood out more so that the error was 
easier to spot).



Regards

Chris



-----Original Message-----
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Dean Chester
Sent: 15 February 2011 00:25
To: Django users
Subject: Django Form Doesn't Render



Hi,

I have written a form in forms.py that looks like this:

class ContractForm(forms.Form):

      title = forms.CharField()

      start_date = forms.DateField()

      end_date = forms.DateField()

      description = forms.CharField(widget=forms.Textarea)

      client = forms.ModelChoiceField(queryset=Client.objects.all())



And in my view (yes i know there are problems with data not being

checked but the aim was to get the client field to display clients

associated with that user):

def addContractTEST(request):

      if request.method == 'POST':

            contractForm = ContractForm(request.POST)

            title = request.POST['title']

            start_date = request.POST['start_date']

            end_date = request.POST['end_date']

            description = request.POST['description']

            client = request.POST['client']

            user = request.user

            contract =

Contract(title,start_date,end_date,description,client,user)

            contract.save()

            return HttpResponseRedirect('../../accounts/profile/')

      else:

            user = request.user

            print user.username

            contractForm = ContractForm()

            return render_to_response('newcontract.html', {'ContractForm':

ContractForm})



And my newcontract.html:

<html>

 <head>

</head>

<body>

      {% if contractForm.errors %}

      <p style="color: red;">

            Please correct the error{{ contractForm.errors|pluralize }} below.

      </p>

      {% endif %}

      <form method="POST" action="">



                  {{ contractForm.as_p }}

            <input type="submit" value="Submit" />

      </form>

</body>

          </html>



But all that appears is my submit button so what am I doing wrong?



Thanks in Advance,

Dean



--

You received this message because you are subscribed to the Google Groups 
"Django users" group.

To post to this group, send email to django-users@googlegroups.com.

To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.

For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to