Is there a HAML implementation for use with Python and Django

Viewed 27067

I happened to stumble across HAML, an interesting and beautiful way to mark up contents and write templates for HTML.

Since I use Python and Django for my web developing need, I would like to see if there is a Python implementation of HAML (or some similar concepts -- need not be exactly identical) that can be used to replace the Django template engine.

12 Answers

You might be interested in SHPAML:

http://shpaml.com/

I am actively maintaining it. It is a simple preprocessor, so it is not tied to any other tools like Genshi. I happen to use it with Django, so there is a little bit of Django support, but it should not interfere with most other use cases.

I'd check out GHRML, Haml for Genshi. The author admits that it's basically Haml for Python and that most of the syntax is the same (and that it works in Django). Here's some GHRML just to show you how close they are:

%html
  %head
    %title Hello World
    %style{'type': 'text/css'}
      body { font-family: sans-serif; }
    %script{'type': 'text/javascript', 'src': 'foo.js'}

  %body
    #header
      %h1 Hello World
    %ul.navigation
      %li[for item in navigation]
        %a{'href': item.href} $item.caption

    #contents
      Hello World!

I would use this one, it seems to be the most standard one: https://pypi.org/project/HamlPy3/0.83.0/

Assuming you're using Python3, you shouldn't haver any issues using it with Django, Flask or even standalone.

You may want to try Hypertag: a new indentation-based language for HTML templating, strongly inspired by HAML. Hypertag has very clean syntax, provides full Django integration and a number of advanced features: native custom tags, DOM manipulation, Python-like imports, complex expressions, filters, control blocks (for, if, try...) and more. See here:

Disclaimer: I'm the author, glad to help if any issues or questions arise.

Related