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
配置路由的 angular 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';也没有找到。当我不使用龙卷风作为服务器时它是有效的。但是在龙卷风服务器中,它不再起作用了。请帮我。谢谢
在 tornado 中,static
目录中的所有文件都是自动提供的,但模板不是这样。您需要一个或多个 RequestHandlers
来提供模板文件(并执行填充模板变量所需的任何服务器端工作。如果没有任何模板变量,也许这些应该是静态文件) .还要记住,angular 会看到 url 提供这些文件的位置,这可能是也可能不是磁盘上的文件名,具体取决于您在 tornado 应用程序中设置路由的方式。
在我的代码中
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
配置路由的 angular jsvar 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';也没有找到。当我不使用龙卷风作为服务器时它是有效的。但是在龙卷风服务器中,它不再起作用了。请帮我。谢谢
在 tornado 中,static
目录中的所有文件都是自动提供的,但模板不是这样。您需要一个或多个 RequestHandlers
来提供模板文件(并执行填充模板变量所需的任何服务器端工作。如果没有任何模板变量,也许这些应该是静态文件) .还要记住,angular 会看到 url 提供这些文件的位置,这可能是也可能不是磁盘上的文件名,具体取决于您在 tornado 应用程序中设置路由的方式。