簡體   English   中英

Python Tornado Angular JS-找不到HTML文件(UI路由器)

[英]Python Tornado Angular JS - Html file not found (ui-router)

用我的代碼

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

startup.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'
        })
}])

index.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'; 也沒有找到。 當我不使用龍卷風作為服務器時,這是工作。 但是在龍卷風服務器中,它不再起作用了。 請幫我。 謝謝

在龍卷風中,將自動提供static目錄中的所有文件,但對於模板而言並非如此。 您需要一個或多個RequestHandlers來提供模板文件(以及完成填充模板變量所需的服務器端工作。如果沒有任何模板變量,則可能應該是靜態文件)。 還要記住,角度將看到提供這些文件的網址,取決於在龍卷風應用程序中設置路線的方式,該網址可能不是磁盤上的文件名。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM