3 ms·
I agree this was frustrating initially. After a certain number of django projects most of the django devs I know use the heck out of it's modularity. If the tem
by jmatt 16y ago
I agree this was frustrating initially. After a certain number of django projects most of the django devs I know use the heck out of it's modularity. If the templating system is driving you insane drop in Jinja2 and go. If it just needs to be tweaked then implement the template command yourself.
I felt confined and frustrated with Django until I realized that it was built with the intention that developers should just crank code on top of it. And not just page code - anything that you need. It's more than just an end product that is just configured, tweaked and templated. Of course ruby similar in the same way... But in comparison to java and .NET web frameworks this was a big change.
Why couldn't they just write it in python instead of inventing strange keywords like "ifequal"?
I think they were trying to get away from the horrid nastiness that had become php or before that cgi. Yet they still wanted to provide options for designers. It definitely has a learning curve and requires the programmer to just roll with it and adopt the "django way". At least until you figure out you can just move to another templating system.
http://docs.djangoproject.com/en/1.2/howto/custom-template-tags/ http://docs.djangoproject.com/en/1.2/howto/custom-template-t...
http://docs.djangoproject.com/en/dev/ref/templates/api/#topic-template-alternate-language http://docs.djangoproject.com/en/dev/ref/templates/api/#topi...
http://djangosnippets.org/snippets/2063/ http://djangosnippets.org/snippets/2063/
- catch23 16y agoShouldn't the included templating system be the one everyone uses? It doesn't make sense to include a templating system if everyone will eventually just replace it with something better. Even though there are alternative rails templating systems out there, I would say a good 80% of the projects out there use the default "erb" mechanism for templates -- it's simple, it's ruby, and it works. Capitalization or minor string manipulation in erb doesn't require one to write a template filter function somewhere else. It's also interesting that in Django 1.2, they pulled away the nastiness of "ifequal" and "ifnotequal". Also, I don't buy their argument that the Django templating system is easier for "designers". Most designers whom I've worked with also do designs in other frameworks and Django's system is no more foreign than jsp, asp, or erb.
- jmatt 16y agoShouldn't the included templating system be the one everyone uses? Agreed. I think they know that this is a weakness. I'd expect it to improve over time. In a similar fashion to them addressing ifequal and ifnotequal in 1.2. Capitalization or minor string manipulation in erb doesn't require one to write a template filter function somewhere else. Personally I'd prefer defining it once somewhere. Then use the function everywhere. Even with the initial code cost. I think this is from past bad experiences. I once "repaired" a million plus line of code enterprise app that had misused some open source code that did date and number coercion (similar to django.contrib.humanize but for ASP). Needless to say the code was a mess and nearly the same code had been mixed in all over the place. The template code, the backend business logic and the asp C# files. After a few days of regexing then testing then fixing then searching then repeating. And then dealing with all the edge and special cases - I'll take a simple defined template function. All that being said - my example is a gnarly enterprise example involving bad code monkeys. So take it with a grain of salt - it's likely that the story isn't applicable to a lot of people here. But still - lesson learned. In the future designers can request template improvements and I'll deliver.
- catch23 16y agoWell, anyone can still write crap code with Django, it doesn't require an enterprise C# language to produce crap. Django templates still have logic that needs to be tested & debugged so the template filter functions don't alleviate all the pain either. Plus, the concept of template filter functions is available in pretty much all web frameworks out there, but it's more painful to use if the templating language forces one to write a filter function every time you need to wield the python language.