javascript - NameError: name "something" is not defined - Web App using Angular JS and Python -
i developing web application using python , angular js. using bottle python framework web server.
my files below:
app.py
import json import os bottle import run, route, template, static_file, request, redirect, get, post import json #import mysqldb ####################### # static file servers # ####################### rootpath = '' @route('/assets/<filepath:path>') def serve_static(filepath): return static_file(filepath, root='static/') ############## # handlers # ############## @route('/') def root(): return template('index.html') def main(): run(host='0.0.0.0', port=55500, debug=true, reloader=true) if __name__ == '__main__': main()
index.html
<!doctype html> <html ng-app="astra"> <head> <title> astra db </title> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.14/angular.min.js"></script> </head> <body ng-controller="mainctrl"> <table> <tr> <th> test case id </th> <th> test case description </th> <th> tester assigned </th> </tr> <tr ng-repeat="testcase in testdb"> <td>{{ testcase.testcaseid }}</td> <td>{{ testcase.testcasedesc }}</td> <td>{{ testcase.tester}} </tr> </table> </body> <script> angular.module('astra', []) .controller('mainctrl', ['$scope', function($scope) { $scope.testdb = [ { "testcaseid" : 1, "testcasedesc" : "to create test case table", "tester" : "veeresh a" }, { "testcaseid" : 2, "testcasedesc" : "to go wonder la", "tester" : "veeresh a" }, { "testcaseid" : 3, "testcasedesc" : "never take meru cab", "tester" : "pallavi bansod" }, { "testcaseid" : 4, "testcasedesc" : "to kill mocking bird", "tester" : "pallavi bansod" }, { "testcaseid" : 5, "testcasedesc" : "to avoid farha khan movie", "tester" : "satyajit patnaik" }, { "testcaseid" : 6, "testcasedesc" : "to talk customer care", "tester" : "mummana santhoshi" },{ "testcaseid" : 7, "testcasedesc" : "to late wherever go", "tester" : "deepa javoor" } ]; }]); </script> </html>
on running python app.py
command prompt, server starts, when hit "localhost:55500" address on browser, throws following errors.
> $ python app.py bottle v0.13-dev server starting (using > wsgirefserver())... listening on http://0.0.0.0:55500/ hit ctrl-c > quit. > > traceback (most recent call last): file "e:\git\pychip\bottle.py", > line 861, in _handle > return route.call(**args) file "e:\git\pychip\bottle.py", line 1741, in wrapper > rv = callback(*a, **ka) file "app.py", line 45, in root > return template('index.html') file "e:\git\pychip\bottle.py", line 3494, in template > return templates[tplid].render(kwargs) file "e:\git\pychip\bottle.py", line 3320, in render > self.execute(stdout, env) file "e:\git\pychip\bottle.py", line 3307, in execute > eval(self.co, env) file "e:\git\pychip\views\index.html", line 15, in <module> > <td>{{ testcase.testcaseid }}</td> nameerror: name 'testcase' not defined > 127.0.0.1 - - [17/mar/2015 09:50:53] "get / http/1.1" 500 1719 > 127.0.0.1 - - [17/mar/2015 09:50:53] "get /favicon.ico http/1.1" 404 749
i getting nameerror exception. can me fix this?
answer problem is:
instead of doing following
@route('/') def root(): return template('index.html')
do this:
@route('/') def root(): return static_file('index.html', root="views/")
as kedar said rightly, bottle , angular have similar templating syntax. need use html pages static files angular templating adhered here.
Comments
Post a Comment