Is there a HAML implementation for use with Python and Django

PythonDjangoDjango TemplatesHaml

Python Problem Overview


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.

Python Solutions


Solution 1 - Python

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.

Solution 2 - Python

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!

Solution 3 - Python

i'm looking for the same. I haven't tried it, but found this:

http://github.com/jessemiller/HamlPy

Solution 4 - Python

You may be interested in Plim. It's a mature python port of Slim.

Solution 5 - Python

This doesn't actually answer your question, but the CSS component of HAML, SASS, can be used freely with any framework. I'm using it right now with Django.

Solution 6 - Python

I'm not sure what the status is of the GHRML bit as I only recently was looking into it. Can't find a repo for it, original developer doesn't have time for it anymore and maintenance was picked up by someone else with an interest in the project. Any extra info on this would be helpful.

Unfortunately, as these things go, I started writing my own HAML style processor ;)

http://dasacc22.wordpress.com/2010/05/03/python-implementation-of-haml/

It's in no way fit for production use at the moment (its literally a 4 day old infant now but like 60+hours crammed in those 4 days) but anyone interested may check it out here. It has a range of features already implemented that make it useful as a toy, and as I clean up the codebase over the next week, I hope to see it replace all my custom XSLT/xpath extensions and templates I have.

Solution 7 - Python

My project, PyHAML, is a Mako preprocessor that gives you very HAML-like syntax. Some of the Ruby doesn't translate very well to Python, so there are some differences, but the spirit is the same.

Solution 8 - Python

I ran across jade doing some node.js work and when returning to Django was looking for something similar. I found [Pyjade][1] and while it's nearly exactly what I'm looking for it handles errors and debugging rather poorly within Django.

[1]: https://github.com/SyrusAkbary/pyjade "PyJade"

Solution 9 - Python

I just made this http://github.com/fitoria/django-haml it's still in very early stage but it works.

Solution 10 - Python

Daniel Skinner's project (mentioned above) seems to have been renamed to DMSL. It seems very powerful, emulates HAML but allows you to use python functions, lambdas, comprehensions etc in it's syntax: https://github.com/dasacc22/dmsl

Solution 11 - Python

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.

Solution 12 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBerView Question on Stackoverflow
Solution 1 - PythonSteve HowellView Answer on Stackoverflow
Solution 2 - PythonChris BunchView Answer on Stackoverflow
Solution 3 - PythonRogerView Answer on Stackoverflow
Solution 4 - PythonMaxim AvanovView Answer on Stackoverflow
Solution 5 - PythonSudhir JonathanView Answer on Stackoverflow
Solution 6 - PythonDaniel SkinnerView Answer on Stackoverflow
Solution 7 - PythonMike BoersView Answer on Stackoverflow
Solution 8 - PythonAaron CaitoView Answer on Stackoverflow
Solution 9 - PythonFitoriaView Answer on Stackoverflow
Solution 10 - PythonzeekayView Answer on Stackoverflow
Solution 11 - PythonAriel MonacoView Answer on Stackoverflow
Solution 12 - PythonMarcin WojnarskiView Answer on Stackoverflow