Search code examples
pythontemplatesfile-extensionjinja2

Is there an idiomatic file extension for Jinja templates?


I need to programatically distinguish between Jinja template files, other template files (such as ERB), and template-less plain text files.

According to Jinja documentation:

A Jinja template doesn’t need to have a specific extension: .html, .xml, or any other extension is just fine.

But what should I use when an explicit extension is required? .py is misleading, and any search including the words "jinja" and "extension" are badly searchwashed by discussion around Jinja Extensions.

I could easily dictate a project-wide convention (.jnj or .ja come to mind) but this is for open source so I don't want to buck the trend if there's already established practice somewhere.


EDIT 1: Again, I understand that the Jinja project — purposefully — does not define a default file extension. I'm asking if there are any unofficial conventions that have emerged for circumstances where one is desired for some project-specific reason.


EDIT 2: Clarification: This is not for HTML content.


Solution

  • 2021 update:: Jinja now officially recommends using the extension .jinja. See docs


    2020 update: Things changed since I wrote this answer, .jinja2 and .j2 are trending.


    Jinja Authors did not define a default extension. Most of Jinja template editors like TextMate extension, Emacs extension, and PyCharm mention no default extension to enforce Jinja highlighting.

    Django already had a request for setting such a default extension, which ended up as a wontfix issue after some debate. I quote from the closing message:

    Filetype detection based on extension is flawed for the very reasons described in these comments, so you have to do some internal inspection, just like MIME type detection works.

    I suggest that you should use your own since there is no common one.