web2py has a more flexible template engine, you can use Python there and does not need to create a tons of template filters to get simple things done. Also in Django the template language sucks a lot because of the limitations.
Let me give an example:
To build a map using google maps API you have to inform the lat/long, for some reason in my database the information was stored as "-23,4500" google maps does not accept it with the comma, so it is easy with Python and web2py.
<script>
map = new GMap({"lat": {{=myplace.lat.replace(",", ".")}}, .....)
</script>
As you can see web2py allowed me to use pure Python code for this.. lets try this in Django...
1. Put the template tags configuration in your settings.py
2. Create a directory called templatetags there
3. Create a module for your template tag
4. import, register, decorate and create your template tag
from django import template
register = template.Library()
@register.filter
def replace(value, args):
value = str(value)
args = str(args)
try:
search, replace = args.split("|")
except Exception:
return value
else:
return value.replace(search, replace)
Template tags/filters are limited functions which receives only one argument, so you have to receive this as string to be able to split them un multiple args.
5. Now in your template file you can use the simple "replace" feature in a weird way
<script>
map = new GMap({"lat": {{ myplace.lat | replace: ",|." }}, .....)
</script>
web2py templates are also very good for some other reasons:
- it allows to create HTML functions
- It has a nice block system
- It allows us to use PURE PYTHON to solve simple things!