【发布时间】:2016-09-06 13:25:36
【问题描述】:
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?
【问题讨论】:
标签: javascript python html angularjs django