framework

Combining jQuery Mobile and Flask-WTF may give you headaches, or why dashes suck in Python variable names

0

I thought developing using Flask on the backend and using jQuery on the front-end (navigator) would be quite easy. In fact it is, but there are some small traps that can take you time to resolve.

A regular case would be, when developing a form, to use Flask with WTForms (Flask-WTF to the rescue!). No problem, you end up with some Jinja2 templates like the following:

<form action="{{url_for('setup')}}" method="POST">
 {{form.channel}}
[...]

Here, you’re converting the variable “channel” which comes from a class defined in the Python Flask code, and thanks to WTForms will convert it to an HTML Select Box. You can also add arguments to that, which will be converted automatically to a pair key/value, for example, you can set {{form.channel(class=’foobar’)}}, which will translate in HTML to:

<select class="foobar" name="channel" [...]

The problem begins when you want to use the themes from jQuery, which are named like “data-theme”. Notice that cool dash (‘-‘)! It prevents you from using the same syntax in Jinja2, as you can’t directly use dashes in variable names. Hopefully, Karol Kuczmarski gave me the answer in the WTForms related Google Group:

{{ form.channel(**{'data-theme': 'b'}) }}

TurboGears and Pylons will merge! (and CleverHarold RIP)

1

Mark Ramm, one of TurboGears‘s core developers announced on TurboGears’s mailing list that they will merge with Pylons! To be more precise, the API of TurboGears will be implemented on top of Pylons. It seems they already made some test/proof of concept that are, as they say “a huge success”. That’s really good news for Python web frameworks development, and a good news for me, as I’ll not have to choose between the two :-

As a sidenote, it seems another framework, CleverHarold has disappeared without anybody noticing. Its domain is parked, and today its Google Group page went off (the last messages were from people asking if the project was still alive).

Update: Noah Gift wrote a nice article about the merge.

Nice introduction article on Pylons

0

Pylons is a cool web framework (one more, besides TurboGears, Django, Zope, etc.). Someone posted on the mailing list a reference to a nice introduction.

Go to Top