[Django]-Django templates syntax highlighting in Eclipse

4👍

The latest PyDev versions include a Django template editor, but it’s not compatible with vanilla Eclipse. You have to use Aptana Studio instead.

Just use http://pydev.org/nightly as update URL, the PyDev and Django template editor packages should be there.

50👍

13👍

For clarity

Django Templates Editor is only available with Aptana 3.0 and later. Pydev in eclipse alone does not support it. Aptana is available as an eclipse plugin or stand alone.

As mentioned by mcoconnor Window -> Preferences -> General -> Editor -> File Associations will give you a list of extensions.

  1. Choose *.html as the file type
  2. Select HTML.Django Templates Editor (Aptana) from Associated editors
  3. Click Default.
  4. Reload any html files you had open in the editor

This should make Aptana treat the Django specific markup correctly instead of reporting errors and also will offer code completion.

6👍

The current recommended way of having a Django Templates Editor with PyDev is by using LiClipse: http://www.liclipse.com (which is a commercial counterpart made to keep PyDev supported — as such it has PyDev standalone and a bunch of other goodies builtin).

Note that by default the html editor in LiClipse is bound to .html and the django templates to .djhtml, so, you can either:

  • open with > LiClipse Django Editor
  • right-click an open editor > languages > Django

Or you can change the default association in:

  • window > preferences > general > editors > file associations > *.html
    • add LiClipse Django editor > set it as default.

-1👍

If you install the Eclipse Web Tools Platform (WTP), it bundles a nice HTML editor, which does 95% of the syntax highlighting you’d want in a Django template. It also includes editors for other common web types, like JS and CSS, which are often nice when working with Django projects. This will also give you code completion and automatic tag closing for the HTML elements, at least.

If you use a .html extension on your template files, you’ll probably get the right editor by default when you open them up, but if not, you can associate the HTML Editor with whatever extension you use in the Window -> Preferences -> General -> Editor -> File Associations interface.

Leave a comment