How to get Angular-Flask app to load html partials?

三世轮回 提交于 2019-12-05 21:00:45

Flask doesn't serve files from the templates folder. If you wish to keep home.html in there, you will need to define a route that matches the URL and serves the file. You can use this as a starting point.

@app.route('/partial/<path:path>')
def serve_partial(path):
    return render_template('/partial/{}'.format(path))

If you don't want to have to create such a view, you can also move the partial templates into static. If your directory structure looked like

static
|---- partial
|     |---- home.html

you'd be able to access the template with

app.config(function($routeProvider){
    $routeProvider.when('/', {
        templateURL: '/static/partials/home.html',
        controller: 'HomeController'    
    }).otherwise({ redirectTo: '/' });
});

Try naming your partials with .tpl.html.

Would changing templateURL to:

templateURL: 'home.tpl.html',

work at all for you?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!