The following ideas may help you to better work onDjango(www.djangoproject.com) projects withGeany.
You can configureGeany to highlight variables and template tags inDjango templates.This helps a lot to differentiate between normalHTML code andDjangotemplate code in the template files.
By default, highlighting ofDjango template tags is disabled because it maycause glitches with other special sorts ofHTML code and not everyoneis using theDjango template language.
To enable that special highlight, you need to adjust theHTML filetype definition file.Either create or edit the file /home/<username>/.config/geany/filedefs/filetypes.htmland add the following few lines (or just adjust the [lexer_properties] section if it alreadyexists):1)
[lexer_properties]lexer.html.django=1
More information about this file, its format and the path, e.g. on Windows,can be found in detail in theGeany manual, section Configuration Files.
You can adjust the styling to some extend using the following settings which should be placed in the [styling] section of filetypes.html:
Explanation:
{% load pages_tags i18n %}
{%
and%}
will be styled withhtml_asp,load
,pages_tags
andi18n
will be styled withpython_identifier and the spaces between withpython_default.
Example:
[styling]# foreground;background;bold;italic or named_style,bold,italichtml_asp=#ff0000python_identifier=keyword_1,italicpython_default=default
The example above makes{%
and%}
styled in red (#ff0000) and the words in between will be styled with the named-stylekeyword_1 (which is by default dark blue) and renders it in italic.
For more information about configuring styles, please check the manualGeany manual, section Filetype configuration.
Tomasz Karbownicki2)created some useful snippets for the filetypes Python andHTML to assist youworking onDjango code and templates.
For convenience, the relevant parts are copied below to easily be inserted intoyourGeany snippet configuration file.To do so, just open the configuration file inGeany by using Tools → Configuration Files → snippets.conf and either paste the contents below completelyor extend the already existing sections Python andHTML.
[Python]# Django models# by Tomasz Karbownicki <tomasz@karbownicki.com>mclass=class %cursor%(models.Model):\n\t'''%cursor%'''\n\n\tdef __unicode__(self):\n\t\treturn self.XXXXX\n\n\tdef get_absolute_url(self):\n\t\treturn"/XXXXX/%s/" % self.slug\n\n\tclass Meta:\n\t\tverbose_name="%cursor%"\n\t\tverbose_name_plural="%cursor%"mchar=%cursor% = models.CharField(max_length=50, verbose_name=u'%cursor%')mint=%cursor% = models.IntegerField(verbose_name=u'%cursor%')mtext=%cursor% = models.TextField(verbose_name=u'%cursor%')mkey=%cursor% = models.ForeignKey(%cursor%, verbose_name=u'%cursor%')mimage=%cursor% = models.ImageField(upload_to='', verbose_name=u'%cursor%')mbool=%cursor% = models.BooleanField(verbose_name=u'%cursor%')mdate=%cursor% = models.DateField(verbose_name=u'%cursor%', help_text='Format daty: 2009-04-28')memail=%cursor% = models.EmailField(verbose_name=u'%cursor%')murl=%cursor% = models.URLField(verbose_name=u'%cursor%')mslug=%cursor% = models.SlugField(verbose_name=u'%cursor%', unique=True) [HTML]# Django templatesif={% if %cursor% %}\n\t\n{% endif %}for={% for sth in %cursor% %}\n\t%cursor%\n{% endfor %}dv={{ %cursor%}}db={% %cursor% %}dbl={% block %cursor% %}\n\t%cursor%\n{% endblock %}trans={% trans"%cursor%" %}com={# %cursor% #}comm={% comment%}ecomm={% endcomment%}
More snippets for Python,HTML and many other languages can be found in this wiki, seeSnippets.
More information about snippets inGeanycan be found in detail in theGeany manual, section Snippets.
Tags for django (version 1.4.1) can be foundhere. For information on using tag files, see theTags section of theGeany User Manual.
Using the greatWeb helper plugin (from theGeany-Plugins package)you can view and test your site directly inGeany without switching to an external browser.
Simply enable theWeb helper plugin inGeany's plugin manager dialog, open it preferences dialogand enable the option “Browser auto reload” (to automatically reload the page when you save a file inGeany).
Then you will get a new tab “Web preview” in the left message window (or whereever you configured the pluginto show up) and you can enter any weg page address, e.g. those of your currently editedDjango project.Below is a screenshot demonstrating the plugin: the opened web page on the left, the template code on the rightand in the terminal window at the bottom,Django's runserver command is running:
This way you can edit yourDjango and template code inGeany as usual and have it automatically shownas web page in theWeb helper plugin without the need of switching to an external browser, andtheDjango debug server can also be ran inGeany, using the embedded terminal.
If you want to add detection/highlighting ofTwig/Symfony2 files (based onDjango's templates) when opening inGeany, add*.html.twig
to theHTML
key in thefiletype_extensions.conf
file. For more information onfiletype_extensions.conf
, see theFiletype extensions section of theGeany User Manual.