gpt4 book ai didi

python - 找不到 HTML 模板

转载 作者:行者123 更新时间:2023-12-01 16:21:45 25 4
gpt4 key购买 nike

当我尝试从模板文件夹加载注入(inject)页面时,出现页面未找到错误。 index.html 页面是我启动服务器时默认启动的页面,它还包含 ng-view,因此我可以注入(inject) Angular 配置中指定的页面。

这是我的项目结构:

 angular_routing/
flask_service.py
static/
script.js
templates/
index.html
home.html
....

这是我的 Angular 路由:

// configure our routes
scotchApp.config(function($routeProvider) {
$routeProvider

// route for the home page
.when('/', {
templateUrl : 'templates/home.html',
controller : 'mainController'
})

// route for the about page
.when('/about', {
templateUrl : 'templates/about.html',
controller : 'aboutController'
})

// route for the contact page
.when('/contact', {
templateUrl : 'templates/contact.html',
controller : 'contactController'
})

.otherwise({
templateUrl: '/',
controller: 'mainController'
});
// $locationProvider.html5Mode(true);
});

顺便说一句,我尝试在 templateUrl 前面加上“/”前缀,但它也不起作用。

最佳答案

templates 文件夹用于存放由 Jinja 从 Flask 渲染的模板文件。它们不作为 Angular 可以访问的普通静态 html 文件提供。将 Angular 模板移至静态文件夹并从那里访问它们。如果您在 Jinja 模板中渲染 Angular 路由代码,则可以使用 url_for 生成 url。

templateUrl: '{{ url_for('static', filename='angular_templates/home.html') }}'
// or if the Angular is complete separate from Flask/Jinja,
// you'll have to just write out the path
templateUrl: 'static/angular_templates/home.html',

关于python - 找不到 HTML 模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31893934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com