[Solved]-Combining Django Templates and Polymer

13👍

See Eric’s answer to this on the polymer-dev mailing list: https://groups.google.com/forum/?fromgroups=#!searchin/polymer-dev/django/polymer-dev/N2R8qknalOI/58ZhC1gWFh4J

Relevant excerpt:

Django 1.5 has support for the verbatim tag. You can wrap your inlined element definitions in that:
https://docs.djangoproject.com/en/1.5/ref/templates/builtins/#verbatim

Example code snippet:

{% verbatim %}
<template repeat="{{item as items}}">
  <my-element name="{{item.name}}"></my-element>
</template>
{% endverbatim %}

<script>
  document.querySelector("template').model = {{items}}; // items here is filled by the server's template.
</script>

3👍

I’m pretty sure this has to do with the fact that Django uses the same {{}} in its templates as Polymer.

0👍

I’m adding this answer as a compliment to the already accepted answer.

You can force django to require a space for it’s template tags. So for any django template tags you have to use {{ variable }} and for polymer you will use {{variable}}.

Here is a very simple module/app I created to “prepare” django for use alongside polymer.

https://github.com/andrewebdev/django-ostinato/blob/2c435dea23319be6e9011e7381afca2b4092b5a2/ostinato/polyprep/init.py

Credit goes to https://github.com/nebrybledu for this suggestion.

👤Andre

Leave a comment