Django Template Auto-completion in Eclipse
I’ve just recently started using Django and I wanted to set up an IDE for some coding niceties.
I already use Eclipse for PHP development, so I installed the PyDev plugin for Eclipse.
Now I get autocomplete in the py files, but when writing the Django html templates, there is no autocomplete for the various template tags.
So here’s a quick guide to adding your own tags in Eclipse.
1. In Eclipse, go to Window->Preferences
2. Go down to Web and XML.
3. Then to HTML files and finally Templates
4. You will see a list of all the various HTML templates there.
5. Click on New.
6. Give your tag a name. It can’t be one that’s already taken, but I found I didn’t have any issues. If you want to keep them all together you could start your tag name with ‘DJ’.
7. Select HTML Tag from the drop down.
8. Give your tag a description.
9. Type in the the tag pattern. If you want the full tag on autocomplete, you might type in {% block ${cursor} %}, otherwise you could start with block, which means you would need to type in the {% and then activate the autocomplete in the HTML editor. The ${cursor} places the cursor where you want it after the tag has been inserted.
10. Click Apply and OK.
11. Test this out in the HTML editor. Press CTRL and Space. You should get a list of available tags. Type b (or what ever the first character is for you tag name), and you’ll see your block tag with the description next to it.
12. Press enter, and your tag will appear.
Hopefully this will make your Django coding a little easier.