本文介绍了Tornado Web服务器在AngularJS运算符表达式中无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行代码(来自 http://plnkr.co/edit/WHcjcEHdny0yhM2Rs95d?p= preview )在2个不同的服务器上-Tornado和Apache.

I run code ( get from http://plnkr.co/edit/WHcjcEHdny0yhM2Rs95d?p=preview) on 2 different server - Tornado and Apache.

index.html:

index.html:

<!DOCTYPE html>
<html ng-app="contestantApp">

  <head>
    <script data-require="[email protected]" 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:

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)龙卷风给我这个错误

1) Tornado give me that error

回溯(最近通话最近一次):

Traceback (most recent call last):

文件"/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/web.py",第665行,呈现html = self.render_string(template_name,** kwargs)

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)

render_string中的文件"/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/web.py"第772行返回t.generate(** namespace)

File "/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/web.py", line 772, in render_string return t.generate(**namespace)

在生成返回execute()中,文件"/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/template.py"第278行

File "/Users/asp/projects/trialsapi/venv/lib/python2.7/site-packages/tornado/template.py", line 278, in generate return execute()

_tt_execute _tt_tmp = raceant.firstName#index.html:14

File "_index_html.generated.py", line 5, in _tt_execute _tt_tmp = contestant.firstName # index.html:14

NameError:未定义全局名称竞争者" ERROR:tornado.access:500 GET/(:: 1)3.61ms

NameError: global name 'contestant' is not defined ERROR:tornado.access:500 GET / (::1) 3.61ms

2)Apache运行良好,并向我展示了我想要的.

2) Apache works good and show me what I want.

我做错了什么?,似乎龙卷风不能与{{}}运算符一起使用?

推荐答案

RequestHandler.render 用于处理Tornado模板,该模板使用 {{}} 进行表达式替换(与Angular相同).如果您使用Angular模板,则可以将此HTML用作静态文件,而不是通过模板引擎运行它,也可以将 {{!"替换为大括号.龙卷风将删除感叹号,其余部分将由角钢处理.

RequestHandler.render is for processing Tornado templates, which use {{ }} for expression substitution (same as Angular). If you use Angular templates, you can either serve this HTML as a static file instead of running it through the template engine, or replace the opening braces with {{!. Tornado will remove the exclamation point and leave the rest alone to be processed by angular.

这篇关于Tornado Web服务器在AngularJS运算符表达式中无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 04:41