Django templates syntax highlighting in Eclipse
I use Eclipse and pydev for django development. This has worked more o开发者_运维知识库r 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?
Django Editor Plugin for Eclipse
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.
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.
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.
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.
精彩评论