Home > django > Django Template Auto-completion in Eclipse

Django Template Auto-completion in Eclipse

November 11th, 2008

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.

django ,

  1. November 12th, 2008 at 09:33 | #1

    Very useful thanks. I have been using Coda for Django as I tried pyDev and it seemed a bit of a faff to get Django projects setup - I am hoping Aptana integrates Django support as they have done for Rails - though I also use Coda for Rails too these days.

    btw - check out pyAMF which makes Flash Remoting a breeze from Python

  2. November 12th, 2008 at 09:39 | #2

    @Jon
    Coda would be nice, but unfortunately I don’t have a Mac (it’s on Santa’s list though!).

    Thanks for the link, it looks interesting.

  3. Adrian
    January 7th, 2009 at 23:28 | #3

    I would love to make use of Django template tag syntax highlighting and code completion but it doesn’t appear as if these options work with the Aptana HTML editor. What HTML editor plugin do you use in Eclipse?

  4. Ciantic
    February 24th, 2009 at 16:18 | #4

    “2. Go down to Web and XML.”
    No such thing in Eclipse Ganymede by default neither in PyDev.

    (Eclipse:
    Version: 3.4.1
    Build id: M20080911-1700)

  5. April 18th, 2009 at 22:26 | #5

    Ciantic: it’s Web > HTML Files > Editor > Templates

  1. No trackbacks yet.