Angular / django新手在这里。我创建了一个django网页,我使用我的html模板,我试图从一个简单的angularjs应用程序和控制器教程渲染值。
尝试将数据打印到页面时,我一直从index.html文件中收到错误。
的index.html
<div ng-app = "" ng-init = "countries = [{locale:'en-US',name:'United States'}, {locale:'en-GB',name:'United Kingdom'}, {locale:'en-FR',name:'France'}]">
<p>Enter your Name: <input type = "text" ng-model = "name"></p>
<p>Hello <span ng-bind = "name"></span>!</p>
<p>List of Countries with locale:</p>
<ol>
<li ng-repeat = "country in countries">
{{ 'Country: ' + country.name + ', Locale: ' + country.locale }}
</li>
</ol>
</div>
<script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="results_app/results_app/js/myApp.js"></script>
<script src="results_app/results_app/js/myCtrl.js"></script>
错误消息:
TemplateSyntaxError at /
could not parse the remainder: ' + country.name + ', Locale: ' + country.locale' from ''Country: ' + country.name + ', Locale: ' + country.locale'
myApp.js
var myApp = angular.module('myApp',[]);
myCtrl.js
myApp.controller('ContactController', ['$scope', function($scope) {
$scope.contacts = ["hi@email.com", "hello@email.com"];
$scope.add = function() {
$scope.contacts.push($scope.contact);
$scope.contact = "";
}
}]);
views.py
def index(request):
return render(request, 'results_app/index.html')
视图还具有序列化模型的类视图集。
为什么会出现此错误?我知道html的语法是正确的。我假设它是不正确的views.py函数?我有不同的方式通过angularjs渲染html吗?
答案 0 :(得分:1)
可能有两个问题可能是请求变量中没有数据,因此请尝试打印在render()时返回的请求变量。 OR
如果数据可用,则您可能需要将ng-repeat更改为
Country: {{country.name }}, Locale: {{country.locale }}