Tornado 网络服务器在使用 AngularJS 运算符表达式时效果不佳
Tornado web server works bad with AngularJS operator expression
我在 2 个不同的服务器 - Tornado 和 Apache 上 运行 代码(从 http://plnkr.co/edit/WHcjcEHdny0yhM2Rs95d?p=preview 获取)。
index.html:
<!DOCTYPE html>
<html ng-app="contestantApp">
<head>
<script data-require="angular.js@1.3.0" data-semver="1.3.0" src="//code.angularjs.org/1.3.0/angular.js"></script>
<script src="/static/js/script.js"></script>
</head>
<body >
<h1>Contestants</h1>
<section ng-controller="ContestantsCtrl as ctrl">
<ul>
<li ng-repeat="contestant in ctrl.contestants">
{{contestant.firstName}} {{contestant.lastName}}
</li>
</ul>
<form ng-controller="ContestantEditorCtrl as editorCtrl">
<h2>New Contestant</h2>
<fieldset>
<label>
First name
<input ng-model="editorCtrl.contestant.firstName">
</label>
<label>
Last name
<input ng-model="editorCtrl.contestant.lastName">
</label>
<button ng-click="editorCtrl.save()">Save</button>
</fieldset>
</form>
</section>
</body>
</html>
script.js :
var app = angular.module('contestantApp', []);
app.controller('ContestantsCtrl', function() {
this.contestants = [
{firstName: 'Rachel', lastName: 'Washington'},
{firstName: 'Joshua', lastName: 'Foster'},
{firstName: 'Samuel', lastName: 'Walker'},
{firstName: 'Phyllis', lastName: 'Reynolds'}
];
});
app.controller('ContestantEditorCtrl', function($scope) {
this.contestant = {};
this.save = function() {
$scope.ctrl.contestants.push(this.contestant);
this.contestant = {};
};
});
1) Tornado 给我那个错误
HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/', version='HTTP/1.1', remote_ip='::1', headers={'Accept-Language': 'en-US,en;q=0.8,fr;q=0.6,ru;q=0.4', 'Accept-Encoding': 'gzip, deflate, sdch', 'Host': 'localhost:8888', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36', 'Connection': 'keep-alive', 'Cookie': '__ngDebug=true', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache'})
回溯(最近调用最后):
File "/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/web.py", line 1332, in _execute result = method(*self.path_args, **self.path_kwargs) File "/Users/asp/projects/trialsapi/tornadoapp.py", line 26, in get self.render("index.html")
File "/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/web.py", line 665, in render html = self.render_string(template_name, **kwargs)
File "/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/web.py", line 772, in render_string return t.generate(**namespace)
File "/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/template.py", line 278, in generate return execute()
File "_index_html.generated.py", line 5, in _tt_execute _tt_tmp = contestant.firstName # index.html:14
NameError: global name 'contestant' is not defined ERROR:tornado.access:500 GET / (::1) 3.61ms
2) Apache 运行良好并向我展示我想要的东西。
我做错了什么? ,看起来龙卷风不适用于 {{}} 运算符?
RequestHandler.render
用于处理Tornado模板,使用{{ }}
进行表达式替换(与Angular相同)。如果您使用 Angular 模板,您可以通过模板引擎将此 HTML 作为静态文件而不是 运行 提供,或者将左大括号替换为 {{!
。 Tornado 将删除感叹号并让其余部分由 angular.
单独处理
你可以用这样的东西覆盖 angular {{ }}。
var app = angular.module().config(function ($interpolateProvider) {$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
您可以使用:
<li ng-repeat="contestant in ctrl.contestants">
{{!contestant.firstName}} {{!contestant.lastName}}
</li>
只需使用“!”在变量名之前。
希望能奏效。
我在 2 个不同的服务器 - Tornado 和 Apache 上 运行 代码(从 http://plnkr.co/edit/WHcjcEHdny0yhM2Rs95d?p=preview 获取)。
index.html:
<!DOCTYPE html>
<html ng-app="contestantApp">
<head>
<script data-require="angular.js@1.3.0" data-semver="1.3.0" src="//code.angularjs.org/1.3.0/angular.js"></script>
<script src="/static/js/script.js"></script>
</head>
<body >
<h1>Contestants</h1>
<section ng-controller="ContestantsCtrl as ctrl">
<ul>
<li ng-repeat="contestant in ctrl.contestants">
{{contestant.firstName}} {{contestant.lastName}}
</li>
</ul>
<form ng-controller="ContestantEditorCtrl as editorCtrl">
<h2>New Contestant</h2>
<fieldset>
<label>
First name
<input ng-model="editorCtrl.contestant.firstName">
</label>
<label>
Last name
<input ng-model="editorCtrl.contestant.lastName">
</label>
<button ng-click="editorCtrl.save()">Save</button>
</fieldset>
</form>
</section>
</body>
</html>
script.js :
var app = angular.module('contestantApp', []);
app.controller('ContestantsCtrl', function() {
this.contestants = [
{firstName: 'Rachel', lastName: 'Washington'},
{firstName: 'Joshua', lastName: 'Foster'},
{firstName: 'Samuel', lastName: 'Walker'},
{firstName: 'Phyllis', lastName: 'Reynolds'}
];
});
app.controller('ContestantEditorCtrl', function($scope) {
this.contestant = {};
this.save = function() {
$scope.ctrl.contestants.push(this.contestant);
this.contestant = {};
};
});
1) Tornado 给我那个错误
HTTPServerRequest(protocol='http', host='localhost:8888', method='GET', uri='/', version='HTTP/1.1', remote_ip='::1', headers={'Accept-Language': 'en-US,en;q=0.8,fr;q=0.6,ru;q=0.4', 'Accept-Encoding': 'gzip, deflate, sdch', 'Host': 'localhost:8888', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36', 'Connection': 'keep-alive', 'Cookie': '__ngDebug=true', 'Pragma': 'no-cache', 'Cache-Control': 'no-cache'})
回溯(最近调用最后):
File "/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/web.py", line 1332, in _execute result = method(*self.path_args, **self.path_kwargs) File "/Users/asp/projects/trialsapi/tornadoapp.py", line 26, in get self.render("index.html")
File "/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/web.py", line 665, in render html = self.render_string(template_name, **kwargs)
File "/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/web.py", line 772, in render_string return t.generate(**namespace)
File "/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/template.py", line 278, in generate return execute()
File "_index_html.generated.py", line 5, in _tt_execute _tt_tmp = contestant.firstName # index.html:14
NameError: global name 'contestant' is not defined ERROR:tornado.access:500 GET / (::1) 3.61ms
2) Apache 运行良好并向我展示我想要的东西。
我做错了什么? ,看起来龙卷风不适用于 {{}} 运算符?
RequestHandler.render
用于处理Tornado模板,使用{{ }}
进行表达式替换(与Angular相同)。如果您使用 Angular 模板,您可以通过模板引擎将此 HTML 作为静态文件而不是 运行 提供,或者将左大括号替换为 {{!
。 Tornado 将删除感叹号并让其余部分由 angular.
你可以用这样的东西覆盖 angular {{ }}。
var app = angular.module().config(function ($interpolateProvider) {$interpolateProvider.startSymbol('{[{').endSymbol('}]}');
您可以使用:
<li ng-repeat="contestant in ctrl.contestants">
{{!contestant.firstName}} {{!contestant.lastName}}
</li>
只需使用“!”在变量名之前。
希望能奏效。