AngularJS 与 Django - 冲突的模板标签 [英] AngularJS with Django - Conflicting template tags

查看:38
本文介绍了AngularJS 与 Django - 冲突的模板标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Django 中使用 AngularJS,但是它们都使用 {{ }} 作为模板标签.是否有一种简单的方法可以更改两者之一以使用其他自定义模板标记?

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 templating tag?

推荐答案

对于 Angular 1.0,你应该使用 $interpolateProvider apis 来配置插值符号:http://docs.angularjs.org/api/ng.$interpolateProvider.

For Angular 1.0 you should use the $interpolateProvider apis to configure the interpolation symbols: http://docs.angularjs.org/api/ng.$interpolateProvider.

这样的事情应该可以解决问题:

Something like this should do the trick:

myModule.config(function($interpolateProvider) {
  $interpolateProvider.startSymbol('{[{');
  $interpolateProvider.endSymbol('}]}');
});

记住两点:

  • 混合使用服务器端和客户端模板很少是一个好主意,应该谨慎使用.主要问题是:可维护性(难以阅读)和安全性(双插值可能会暴露一个新的安全向量 - 例如,虽然服务器端和客户端模板的转义本身可能是安全的,但它们的组合可能不安全).
  • 如果您开始使用在模板中使用 {{ }} 的第三方指令(组件),那么您的配置将破坏它们.(修复待定)
  • mixing server-side and client-side templates is rarely a good idea and should be used with caution. The main issues are: maintainability (hard to read) and security (double interpolation could expose a new security vector - e.g. while escaping of serverside and clientside templating by themselves might be secure, their combination might not be).
  • if you start using third-party directives (components) that use {{ }} in their templates then your configuration will break them. (fix pending)

虽然我们对第一个问题无能为力,除了警告人们,我们确实需要解决第二个问题.

While there is nothing we can do about the first issue, except for warning people, we do need to address the second issue.

这篇关于AngularJS 与 Django - 冲突的模板标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆