gpt4 book ai didi

javascript - 名称错误 : name "something" is not defined - Web App using Angular JS and Python

转载 作者:行者123 更新时间:2023-12-03 10:33:53 25 4
gpt4 key购买 nike

我正在使用 Python 和 Angular JS 开发一个 Web 应用程序。我正在为我的 Web 服务器使用 Bottle Python 框架。

我的文件如下:

应用程序.py

import json
import os
from 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 a test case table",
"tester" : "Veeresh A"
},
{
"testCaseID" : 2,
"testCaseDesc" : "To go to wonder la",
"tester" : "Veeresh A"
},
{
"testCaseID" : 3,
"testCaseDesc" : "Never take a Meru Cab",
"tester" : "Pallavi Bansod"
},
{
"testCaseID" : 4,
"testCaseDesc" : "To kill a mocking bird",
"tester" : "pallavi bansod"
},
{
"testCaseID" : 5,
"testCaseDesc" : "To avoid a farha khan movie",
"tester" : "Satyajit Patnaik"
},
{
"testCaseID" : 6,
"testCaseDesc" : "To talk to the customer care",
"tester" : "Mummana Santhoshi"
},{
"testCaseID" : 7,
"testCaseDesc" : "To be late to wherever you go",
"tester" : "Deepa Javoor"
}
];



}]);

</script>
</html>

从命令提示符运行 python app.py 时,服务器启动,但是当我在浏览器上输入“localhost:55500”地址时,它会抛出以下错误。

> $ python app.py Bottle v0.13-dev server starting up (using
> WSGIRefServer())... Listening on http://0.0.0.0:55500/ Hit Ctrl-C to
> 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' is 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

我收到名称错误异常。有人能帮我解决这个问题吗?

最佳答案

我的问题的答案是:

而不是执行以下操作

@route('/')
def root():
return template('index.html')

这样做:

@route('/')
def root():
return static_file('index.html', root="views/")

正如 kedar 所说,bottle 和 Angular 具有相似的模板语法。因此,我需要将 HTML 页面用作静态文件,以便在此处坚持 Angular 模板。

关于javascript - 名称错误 : name "something" is not defined - Web App using Angular JS and Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29091312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com