AngularJS with Django - Conflicting template tags

前端 未结 12 2262
南笙
南笙 2020-11-22 13:39

I want to use AngularJS with Django however they both use {{ }} as their template tags. Is there an easy way to change one of the two to use some other custom

12条回答
  •  日久生厌
    2020-11-22 14:19

    I found the code below helpful. I found the code here: http://djangosnippets.org/snippets/2787/

    """
    filename: angularjs.py
    
    Usage:
        {% ng Some.angular.scope.content %}
    
    e.g.
        {% load angularjs %}
        

    {% ng yourName %}

    """ from django import template register = template.Library() class AngularJS(template.Node): def __init__(self, bits): self.ng = bits def render(self, ctx): return "{{%s}}" % " ".join(self.ng[1:]) def do_angular(parser, token): bits = token.split_contents() return AngularJS(bits) register.tag('ng', do_angular)

提交回复
热议问题