form.as_table not displaying in template

540 views
Skip to first unread message

Explore

unread,
Apr 22, 2008, 12:02:13 PM4/22/08
to Django users
Hi. I am new to django and I am trying to get a handle around the form
processing. I am using the svn trunk Revision: 7419 on Windows with
the development server. I have a views.py setup in my app that looks
like this:

form = TestingForm()
print form.as_table()
print form.as_table
return render_to_response('testing.html', { 'form':TestingForm })


When I look at the output of this on my development server I see that
form.as_table prints out the object info and form.as_table() prints
out the tr tags for the form. So this looks like form.as_table() is
working as it should when printing to the command line.

However, when I try to use this in my template testing.html like this:

test 1<br/>
<table>
{{ form.as_table }}
</table>

nothing prints out (maybe because it is trying to print the object
instead of calling the method?) However, when I try:

form.as_table() I get the following syntaxerror:
Could not parse the remainder: '()' from 'form.as_table()'

How can I use form.as_table in my template?

I am new to both python and django so any help would be appreciated.
Thanks very much.

Kenneth Gonsalves

unread,
Apr 22, 2008, 12:21:06 PM4/22/08
to django...@googlegroups.com

On 22-Apr-08, at 9:32 PM, Explore wrote:

> test 1<br/>
> <table>
> {{ form.as_table }}
> </table>
>
> nothing prints out (maybe because it is trying to print the object
> instead of calling the method?)

this is correct. It should work, but to diagnose you should post the
full template and the full view

--

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/code/

Karen Tracey

unread,
Apr 22, 2008, 12:20:08 PM4/22/08
to django...@googlegroups.com
On Tue, Apr 22, 2008 at 12:02 PM, Explore <explore....@gmail.com> wrote:

Hi. I am new to django and I am trying to get a handle around the form
processing.  I am using the svn trunk Revision: 7419 on Windows with
the development server.  I have a views.py setup in my app that looks
like this:

 form = TestingForm()
 print form.as_table()
 print form.as_table
 return render_to_response('testing.html', { 'form':TestingForm })


You are passing the TestingForm class into the template context instead of the form instance you created.  This should be:

return render_to_response('testing.html', { 'form': form })

Karen
 

Malcolm Tredinnick

unread,
Apr 22, 2008, 12:20:21 PM4/22/08
to django...@googlegroups.com

On Tue, 2008-04-22 at 09:02 -0700, Explore wrote:
> Hi. I am new to django and I am trying to get a handle around the form
> processing. I am using the svn trunk Revision: 7419 on Windows with
> the development server. I have a views.py setup in my app that looks
> like this:
>
> form = TestingForm()
> print form.as_table()
> print form.as_table
> return render_to_response('testing.html', { 'form':TestingForm })

You're passing in a class to the template, rather than an instance of
the form. Your need to pass the "form" variable via the dictionary, not
the TestingForm class.

Regards,
Malcolm

--
I just got lost in thought. It was unfamiliar territory.
http://www.pointy-stick.com/blog/

Message has been deleted

Explore

unread,
Apr 22, 2008, 1:27:20 PM4/22/08
to Django users
Thank you all for your quick responses. I was passing the class
instead of the instance. Everything is working great now!

On Apr 22, 12:20 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
Reply all
Reply to author
Forward
0 new messages