views:

41

answers:

1

I feel like I am missing something really obvious. I'm trying to use the WTForms template extensions with Django. I have a project on my development server which is working great (IE the extensions are working properly) but when I put it out on a test server, suddenly they are broken. Both servers have the same versions of Python, Django, WTForms installed. Settings.py is the same on both, including:

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'wtforms.ext.django',

)

Within the template, I am doing:

{% load wtforms %}

{% autoescape off %}


<form id='returnform' action='{{form.action}}' method='POST' ENCTYPE="multipart/form-data">

And in the actual form, action is defined as:

class UserForm(wtforms.Form):
    #Some fields and such here
    def action(self):
        return "/Admin/H/requests/"

So, on the Dev server, my page loads with the proper 'action=url' like I expect. But on my test server, it returns a page that has

'action=<bound method UserForm.action of <pulseman.admin.forms.UserForm object at 0x9c8598c>>'

Any thoughts on what I'm missing here? Thanks.

+1  A: 

I'm not sure what the cause of this is, but I can assure you it's not WTForms. We don't do anything funky with the classes, so if Django isn't invoking action properly, it's something in Django. Have you tried renaming the function, to see if it's a weird issue with the name "action"?

Alternately, you could try turning action into a property using the @property decorator, or simply define the action as a string on the class.

With that said, I would suggest not embedding URLs into the form on the python side. This is better solved by using URL reversing with the {% url %} templatetag.

Thomas Johansson