Django的不Angularjs工作 [英] Django not working with Angularjs

查看:167
本文介绍了Django的不Angularjs工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打开文件 angular.html Chrome浏览器中,HTML正常工作的angularjs,显示表中的信息的阵列。然而,当我使用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 但显示一个空白页。

推荐答案

的问题是,Django和AngularJS双方分担模板变量替换相同的语法。

The problem is that both Django and AngularJS share the same syntax for variable substitution in templates.

最简单的办法是告诉Django不使用它的语法的地方,你需要使用angularjs变量替换 - 换句话说,使用的 逐字标记

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屋!

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