1

Angular/django newbie here. I have created a django web page and I using my html template I am trying to render values from a simple angularjs app and controller tutorial.

I keep getting an error from the index.html file when trying to print data to the page.

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>

the error message:

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')

The views also has class viewsets from serializing my models.

Why does this error come up? I know the syntax of the html is correct. I assume it is the views.py function that is incorrect? Is there a different way i have to render the html through angularjs?

trouselife
  • 971
  • 14
  • 36

1 Answers1

1

There may be two problems may be data is not there in your request variable so try to print request variable which you have return while render(). OR

If data is available then you may need to change ng-repeat as

Country: {{country.name }}, Locale: {{country.locale }}
Piyush S. Wanare
  • 4,703
  • 6
  • 37
  • 54