未找到HTML模板 [英] HTML template not found

查看:629
本文介绍了未找到HTML模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



这是我的项目结构:

  angular_routing / 
flask_service.py
static /
脚本.js
templates /
index.html
home.html
....

这是我的角度路由:

$ $ p $ //配置我们的路线
scotchApp。 config(function($ routeProvider){
$ routeProvider

//主页路由
.when('/',{
templateUrl:'templates / home.html',
controller:'mainController'
})

//关于页面的路由
.when('/ about',{
templateUrl:'templates / about.html',
控制器:'aboutController'
})

//联系页面的路由
.when('/ contact',{
templateUrl:'templates / contact。 html',
controller:'contactController'
})

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

顺便提一句,我试着用'/'作为templateUrl的前缀,但是它也不起作用。 / p>

解决方案

templates文件夹是由Flask的Jinja渲染的模板文件。它们不作为可以被Angular访问的普通静态html文件。将Angular模板移动到静态文件夹并从那里访问它们。您可以使用 url_for 来生成url,如果您要在Jinja模板中呈现Angular路由代码。



<$ p $或者如果Angular与Flask / Jinja是完全独立的,那么就可以使用这个模板,
//你必须写出路径
templateUrl:'static / angular_templates / home.html',


I get page not found error when I try to load an injected page from my templates folder. index.html page is the page launched by default when I start the server and it also contains ng-view, so I can inject the pages specified in the angular config.

Here is my project structure:

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

This is my angular routing:

// 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);
    });

BTW, I tried prefixing the templateUrl with a '/' but it didn't work either.

解决方案

The templates folder is for template files that will be rendered by Jinja from Flask. They are not served as normal static html files that would be accessible to Angular. Move the Angular templates to the static folder and access them from there. You can generate the urls with url_for if you're rendering the Angular routing code in a Jinja template.

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

这篇关于未找到HTML模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆