Django templates syntax highlighting in Eclipse
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.
- Choose *.html as the file type
- Select HTML.Django Templates Editor (Aptana) from Associated editors
- Click Default.
- 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.
Related videos on Youtube
Comments
-
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?
-
Oben Sonne over 11 yearsPossible duplicate: stackoverflow.com/q/1670643/151299
-
-
rob about 13 yearsPersonally, 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 about 13 yearswell, the 5% remaining are the django templating syntax that I'm missing.
-
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 over 12 yearsI 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 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 over 10 yearsThis plugin is currently broken and hangs Eclipse when entering `<form action="{%%}". See code.google.com/p/django-editor/issues/detail?id=12
-
ChrisR over 10 yearsThe bug @donturner mentioned also extends to opening templates which contain django template logic in attributes.
-
donturner over 9 yearsJust to add that the plugin is now fixed, and it's awesome. I even use it for plain old HTML highlighting.