Question

I'm trying to use WTForms with webapp without much luck.

I would like to be able to use the form_field templatetag, as shown in the documentation:

{% form_field form.username class="big_text" onclick="do_something()" %}

I've got WTForms installed fine in my application, but its Django template tags isn't working for me. Does anyone have instructions on how to get this installed?

If I can't get this working, I will probably give up and switch to Jinja2 templates. The reason we have kept with Django so far is to limit the number of dependencies as much as possible.


Here's what I've tried so far:

I've install Django 1.1 locally and enabled it per the documentation.

I tried adding INSTALLED_APPS = ['wtforms.ext.django'] to my settings.py - no effect.

I tried registering the wtforms templatetag manually:.

register = webapp.template.create_template_register()

from wtforms.ext.django.templatetags import wtforms

register.tag('form_field', wtforms.do_form_field)

This gave me an error: InvalidTemplateLibrary: Could not load template library from template_helpers, No module named django.templatetags

So I tried copying and pasting the template tags into my own code, and I got the error TemplateSyntaxError: Could not parse the remainder: ' form.foobar' from 'form_field form.foobar.

However, I don't think the templatetag registration worked, because the error was the same without that code.


Update: I'm leaving this question up in case someone on the internet can some day answer it, but I switched to Jinja2 and now everything works perfectly. Webapp with Django templates is dead to me. ;-)

Was it helpful?

Solution

I recommend jinja2 templates over django: http://jinja.pocoo.org/ It's based on the django templates but more powerful and easy to use. I don't think it's a good idea to use Django templates without the django stack. Also, if you want a more structured framework, a VERY nice minimalist framework is Flask: http://www.pocoo.org/projects/flask/#flask. I can't praise those two libraries enough. I worked a long time in Django and found this combo to be very refreshing and succinct.

P.S. this should be a very simple process to port over. It took me 10 minutes to port over a webapp site when I just found out about Flask.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top