找不到HTML模板

时间:2015-08-08 14:09:17

标签: python angularjs flask angular-routing

当我尝试从模板文件夹中加载注入的页面时,我发现页面未找到错误。 index.html页面是我启动服务器时默认启动的页面,它还包含ng-view,所以我可以注入angular config中指定的页面。

这是我的项目结构:

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

这是我的角度路由:

// 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前加上' /'但它也没有用。

2 个答案:

答案 0 :(得分:1)

模板文件夹用于模板文件,将由Jinja从Flask呈现。它们不能作为Angular可访问的普通静态html文件。将Angular模板移动到静态文件夹并从那里访问它们。如果您在Jinja模板中呈现Angular路由代码,则可以使用url_for生成网址。

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',

答案 1 :(得分:-1)

检查路由器是否正在访问正确的页面。您可以通过开发者控制台在Chrome中执行此操作,然后使用“网络”标签。

相关问题