Hacker News new | ask | show | jobs
by monkeyfacebag 4797 days ago
I don't know if it's possible but, in general, it's not a good idea to mix server-side and client-side templating. The Angular guys discuss this in one of the videos on the Angular channel (I found it for you here: http://www.youtube.com/watch?feature=player_detailpage&v...). The two reasons seem to be first, it's not clean and second, it's easy to introduce security issues.

If I want to have a page that has both server-side templating and client-side templating, I push the ng-app directive down into the DOM and assert that Angular has "ownership" of that portion of the page. I can't remember what Django's templating engine supports, but in Jinja2, you can create a {% raw %} {% endraw %} block that tells Jinja2 not to parse any delimiters in the block (I'm sure Django has something like this, I just can't recall what it is). This makes it pretty easy to separate out Angular's purview from the server's purview even on a single page.

2 comments

That security concern is nonsense. Use {% verbatim %} as noted below for angular templates (there's plenty of backports for Django <1.5). I have django templates fill in runtime parameters (csrf_tokens, etc) all the time.
Django 1.5 introduced {% verbatim %} {% endverbatim %} which takes care of what you describe. https://docs.djangoproject.com/en/dev/ref/templates/builtins...