angularjs无法找到模板目录,烧瓶后端 [英] angularjs unable to find templates directory, flask as backend

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

问题描述

我用的烧瓶后端和客户端angularjs

I am using flask as backend and angularjs on client-side

我的目录结构:

露:

  ->app.py

  ->templates
    ->hello.html
    ->test.html

  ->static
    ->js
      ->directives.py
    ->lib
      ->angular.js

我app.py文件:

my app.py file:

from flask import Flask, make_response,render_template
@app.route("/aboutUs")
def aboutUs():
    return render_template("test.html", title="test page")

我directives.py文件:

my directives.py file :

angular.module('components',[])
    .directive("helloWorld",function($scope,$log){
        $scope.$log = $log;
        return{
            restrict:"A",
            templateUrl:"templates/hello.html"
        }
    })

angular.module('testApp',['components'])

烧瓶能够正确渲染的test.html模板,但角度是显示hello.html的,模板没有发现错误

Flask was able to render the test.html template properly, but angular was showing hello.html, template not found error

推荐答案

如果您的模板 hello.html的包含了一些Jinja2的标记,那么它需要通过烧瓶呈现。然后,你需要以拥有它呈现增加一个 @ app.route

1. Jinja template

If your template hello.html contains some Jinja2 markup, then it needs to be rendered by flask. Then you need to add an @app.route in order to have it rendered.

@app.route("/hello")
def hello():
    return render_template("hello.html")

然后你需要为指向你好 URL在你的角度指令。

And then you need to point to the hello url in your angular directive.

templateUrl:"/hello"

2。角模板

如果您的模板仅仅包含HTML(无Jinja2的标记),那么它不应该在模板文件夹,但是在静态文件夹中的 即可。类似静态/模板/ hello.html的

2. Angular Template

If your template only contains html (no Jinja2 markup), then it should not be in the templates folder but in the static folder. Something like static/templates/hello.html.

那么你的烧瓶应用程序将返回 hello.html的使用模板/ hello.html的 URL文件时在你的指令。

Then your flask app will return the hello.html file when the templates/hello.html url is used in your directive.

这篇关于angularjs无法找到模板目录,烧瓶后端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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