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 = ["[email protected]", "[email protected]"];

    $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?

0

1 Answer 1

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 }}
Sign up to request clarification or add additional context in comments.

2 Comments

the ng-repeat change does not work. I dont understand how to 'print request variable'?
just write print request that's it and do runserver and check server log

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.