AngularJS with Django - Conflicting template tags

前端 未结 12 2258
南笙
南笙 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:24

    We created a very simple filter in Django 'ng' that makes it easy to mix the two:

    foo.html:

    ...
    
    {{ django_context_var }} {{ 'angularScopeVar' | ng }} {{ 'angularScopeFunction()' | ng }}
    ...

    The ng filter looks like this:

    from django import template
    from django.utils import safestring
    
    register = template.Library()
    
    
    @register.filter(name='ng')
    def Angularify(value):
      return safestring.mark_safe('{{%s}}' % value)
    

提交回复
热议问题