【问题标题】:Python Tornado Angular JS - Html file not found (ui-router)Python Tornado Angular JS - 找不到 Html 文件(ui-router)
【发布时间】:2017-03-24 02:48:02
【问题描述】:

在我的代码中

File Structure:
App-
 |--- static
 |      |--- css
 |      |--- js
 |            |--- app.js 
 |   
 |--- templates
 |      | --- header.html
 |      | --- template.html
 |      | --- footer.html
 |      | --- index.html
 |--- startup.py

启动.py: 这是告诉龙卷风在哪里找到文件的设置

settings = dict (
    template_path = os.path.join(os.path.dirname(__file__), "templates"),
    static_path = os.path.join(os.path.dirname(__file__), "static"),
    debug = True
)

app.js: 这是使用ui-router配置路由的角度js

var app = angular.module('app', [
    'ui.router'
  ]);

app.config(['$urlRouterProvider', '$stateProvider', 
    function($urlRouterProvider, $stateProvide) { 
        $urlRouterProvider.otherwise('/');

        $stateProvide
        .state('template', {
            url:'/',
            templateUrl: 'template.html',
            controller: 'myController'
        })
}])

索引.html: 这是模板文件

<!DOCTYPE html>
<html>

<head >
    <title>
    </title>

    <script type="text/javascript" src=" {{ static_url('lib/js/angular.js') }}"></script>
    <script type="text/javascript" src=" {{ static_url('lib/js/angular-ui-router.js') }}"></script>
    <script type="text/javascript" src=" {{ static_url('lib/js/jquery-3.2.0.js') }}"></script>
    <script type="text/javascript" src=" {{ static_url('lib/js/bootstrap.js') }}"></script>
    <script type="text/javascript" src=" {{ static_url('js/app.js') }}"></script>

    <link rel="stylesheet" type="text/css" href="{{ static_url('lib/css/bootstrap.css') }}">
    <link rel="stylesheet" type="text/css" href="{{ static_url('css/app.css') }}">

</head>


<body ng-app='app'>

    <header ng-include src="'header.html'"></header>

    <div ui-view>

    </div>
    <footer ng-include src="'footer.html'"></footer>
</body>

现在我的问题是: 找不到我在 index.html 中使用 ng-include 的 header.html 和 footer.html。在 app.js 中,templateUrl: 'template.html';也没有找到。当我不使用龙卷风作为服务器时,它是有效的。但是在龙卷风服务器中,它不再起作用了。请帮我。谢谢

【问题讨论】:

    标签: python html angularjs tornado


    【解决方案1】:

    在 tornado 中,static 目录中的所有文件都会自动提供,但模板并非如此。您需要一个或多个RequestHandlers 来提供模板文件(并执行填写模板变量所需的任何服务器端工作。如果没有任何模板变量,也许这些应该是静态文件)。还要记住,angular 会看到提供这些文件的 url,这可能是也可能不是磁盘上的文件名,具体取决于您在 tornado 应用程序中设置路由的方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-28
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 2017-06-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多