« EuroDjangoCon Talk: Testing Django | Migrating Django Test Fixtures Using South »
Any sufficiently large Django project starts to have a wide variety of Template Tags and Filters. Even Django ships with a dizzying array of them that allow you to do all sorts of fun and interesting things. Ellington, our CMS at work, has a ton, and I've been thinking about ways to make tags and filters a bit more accessible to people who are using the CMS.
I'm thinking along the lines of people who are tech savvy, but who were just hit with a huge wall of tags and filters to look at. I want them to be able to really easily play with the functionality and see what it does.
I created a proof of concept playground for tags and filters in the django admin. It is released as a simple third party app that I have up on Github. Here is a small 1:40 minute screencast that explains what I did:
Admin Playground from Eric Holscher on Vimeo.
It gives you a "Play" link next to each of the tags and filters in the admin. Once you click on that, if the docstring for the tag has a code example, it attempts to parse that out. This allows you to easily test out the examples that you should have in the docstrings for your tags.
It displays the docstring above the input areas and allows you to input context variables (naively) and render the template. It uses Jquery to do an ajax post and response that is displayed on the right side of what the output of the template would be.
A simple example with the Add Template Tag:

This is very hacky and basic code. Totally just a proof of concept and might not work for you. I think that the ideas are worthwhile, and something that could be included in Django at some point.
Currently the context values are just being parsed at the : and split into a dictionary. If anyone knows a good way to turn a basic list like this (using YAML?) into Django objects, then I would be all ears. I thought about it a little bit but couldn't think of an elegant solution.
Also the parsing of the templatetag syntax out of the templates is incredibly simplistic. If I took some time and played around with ReST I'm sure I could figure out a better way to do that (Pulling out the "code blocks" somehow?). But a basic regex worked well enough to get the idea done.
Feedback welcome.
Posted at 1:32 p.m. on May 24, 2009
Comments: 4
Tags: admin , django , idea , playground , proof-of-concept
The problem with Django's Template Tags
Making Template Tag Parsing Easier
The times, they are a changin
Welcome to the home of Eric Holscher on the web. I talk about software development, mostly in the realm of Django. I am interested in the real time web, testing, mobile apps, and other things.
Why Read the Docs matters
2 weeks, 1 day ago (Comments: 7)
Read the Docs Update
10 months ago (Comments: 2)
Using Reviewboard with Git
1 year ago (Comments: 0)
Read the Docs Updates
1 year ago (Comments: 1)
Handling Django Settings Files
1 year ago (Comments: 12)
Required Reading
1 year, 2 months ago (Comments: 0)
Using Haystack to index non-database content
1 year, 2 months ago (Comments: 4)
Correct commands to check out and update VCS repos
1 year, 2 months ago (Comments: 0)
Site upgrades
1 year, 2 months ago (Comments: 0)
Building a Django App Server with Chef: Part 4
1 year, 2 months ago (Comments: 1)
Setting up Django and mod_wsgi
Building a Django App Server with Chef: Part 1
Screencast: Django Command Extensions
Big list of Django tips (and some python tips too)
Handling Django Settings Files
Lessons Learned From The Dash: Easy Django Deployment
Large Problems in Django, Mostly Solved: Delayed Execution
Building a Django App Server with Chef: Part 2


Comments
1 Greg says...
Perfect to teach django !
Posted at 8:13 p.m. on May 24, 2009
2 Alex Gaynor says...
I'm not sure I understand the point, isn't this what the command line is for? Trying to program in the browser is, in my opinion, idiotic. If you don't know what your template tags and filters do, you have a documentation problem, not a tools problem.
Posted at 8:28 p.m. on May 24, 2009
3 Eric Holscher says...
Greg: Indeed.
Alex: It's not for you :) I agree that programmers and the people writing the code won't really use this. But for people who aren't super technical but are tasked with writing templates, it's a really low barrier to entry way to test out template tags. If they are trying to accomplish a certain goal, they can see if it works in a couple seconds, instead of having the to set up an environment and everything in order to test.
Posted at 8:36 p.m. on May 24, 2009
4 Thejaswi Puthraya says...
Great idea!!! The template system was written with designers in mind and the browser is their playground. So I think this would be very helpful for them.
Posted at 7:40 a.m. on May 26, 2009