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

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

问题描述

我想使用的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?

推荐答案

有关角1.0,你应该使用$ interpolateProvider API来配置插值符号:<一href=\"http://docs.angularjs.org/api/ng.%24interpolateProvider\">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.

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

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