Django templates syntax highlighting in Eclipse

15,856

Solution 1

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.

Solution 2

Django Editor Plugin for Eclipse

Solution 3

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.

Solution 4

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.
Share:
15,856

Related videos on Youtube

abolotnov
Author by

abolotnov

it's a long story haha.

Updated on October 20, 2020

Comments

  • abolotnov
    abolotnov over 3 years

    I use Eclipse and pydev for django development. This has worked more or less ok, including debugging. Syntax highlighting doesn't seem to work everywhere though. I couldn't get any highlighting for the templates thought. Is there a way to get the highlighting and code suggestions for the templates?

  • rob
    rob about 13 years
    Personally, I found Aptana studio quite invasive. For instance, the way it changes the window fonts, without taking into account of the Eclipse settings, and in general the feeling that it was not using standard Eclipse interface and approach.
  • abolotnov
    abolotnov about 13 years
    well, the 5% remaining are the django templating syntax that I'm missing.
  • AndiDog
    AndiDog about 13 years
    @Roberto: I didn't say Aptana was good. Actually I also prefer standard Eclipse myself, HTML highlighting is enough for me. (If Django templates grow so complex that you need highlighting, you're doing it wrong.)
  • Steve Bennett
    Steve Bennett over 12 years
    I found it unintuitive to install aptana as an eclipse plugin. At the moment, you go here: aptana.org/products/studio3/download then click the "eclipse plug-in version" radio button.
  • vergenzt
    vergenzt almost 11 years
    +1 This is by far the best solution, for me at least. Also works for Jinja2 templates, as they have essentially the same syntax.
  • donturner
    donturner over 10 years
    This plugin is currently broken and hangs Eclipse when entering `<form action="{%%}". See code.google.com/p/django-editor/issues/detail?id=12
  • ChrisR
    ChrisR over 10 years
    The bug @donturner mentioned also extends to opening templates which contain django template logic in attributes.
  • donturner
    donturner over 9 years
    Just to add that the plugin is now fixed, and it's awesome. I even use it for plain old HTML highlighting.