Hy introduces a List that gives you all the power of macros and the elegant Lisp syntax while enabling the full power of Python.
Although it's easy enough to use Python libraries in Hy, you just import them as you would in Python, I was weary of using a full framework outside it's native language. To prove out this concept, I followed the official django tutorial using Hy.
To my surprise I only ran into minor issues. The rest of the project worked flawlessly.
If you just want to see the code, you can take a look at my hy-django github repo. There you will find the finished project along with branches for each of the tutorial parts.
Why Hy with Django?
I personally love lisp syntax. It is consistent and simple without edge cases like Python's lambadas.
If you're a fan of function programming, like I am, then you will love the decisions the Hy devs made. They tried to keep the spirit of Python while taking inspiration from Clojure and Scheme to make higher order functions and other abstractions natural.
Being a lisp, Hy brings macros. These abstraction generate code on the fly, reduce repetition, and enable expressing ideas in the best way for the problem. It's hard to fully describe their usefulness, but Paul Graham came close:
"The shape of a program should reflect only the problem it needs to solve. Any other regularity in the code is a sign, to me at least, that I'm using abstractions that aren't powerful enough– often that I'm generating by hand the expansions of some macro that I need to write."
Using Hy with Django
Django handle Hy and Python files the same, for the most part. Things like migrations just work.
I ran into two areas that required some fiddling however.
settings.py to remain in the base app. To get this
working with Hy files you have to add
import hy at the top of the
manage.py test does not pick up test files automatically. To get it to work,
you need to add a
tests folder to each app, which is good practice anyways,
__init__.py file that imports all the Hy test modules.
I ended up using relative imports with a glob pattern:
You can write the rest of the application in pure Hy. Happy hacking!