Django没有使用Angularjs [英] Django not working with Angularjs
问题描述
当我使用Chrome打开angularjs文件 angular.html
时,html正常工作,显示表中的信息数组。然而,当我使用Django时,同样的angular.html文件,angularjs不会在表中显示信息数组。我不知道该怎么办?
When I open the file angular.html
the angularjs with Chrome, the html work normally, showing the array of information in the table. However, when I use Django, the same angular.html file, angularjs does not show the array of information in the table. I do not know what can I do?
文件 angular.html
<html ng-app>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"></script>
<script>
function tabela($scope){
$scope.linhas2=[["Nexus S1","Oi1"],["Nexus S2","Oi2"],["Nexus S3","Oi3"]]
}
</script>
</head>
<body>
<div ng-controller="tabela">
<table>
<tr ng-model="item2" ng-repeat="item2 in linhas2">
<td ng-repeat="item3 in item2">{{ item3 }}</td>
</tr>
</table>
</div>
</body>
</html>
文件 views.py
from django.shortcuts import render_to_response
def ang(request):
return render_to_response("angular.html")
文件 urls.py
from django.conf.urls import patterns, include, url
urlpatterns = patterns('',
url(r'^angular/','bvmfconsulta.views.ang'),
)
Django发现 angular.html
,但显示一个空白页。
The Django finds angular.html
but shows a blank page.
推荐答案
问题是Django而AngularJS在模板中具有与变量替换相同的语法。
The problem is that both Django and AngularJS share the same syntax for variable substitution in templates.
最简单的选择是告诉Django不要在需要使用angularjs变量替换的地方使用它的语法 - 换句话说,使用 verbatim
标签:
The easiest option would be to tell Django not to use it's syntax in places you need to use angularjs variable substitution - in other words, use verbatim
tag:
{% verbatim %}
<div ng-controller="tabela">
<table>
<tr ng-model="item2" ng-repeat="item2 in linhas2">
<td ng-repeat="item3 in item2">{{ item3 }}</td>
</tr>
</table>
</div>
{% endverbatim %}
查看其他选项:
- Integrate AngularJS with Django
这篇关于Django没有使用Angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!