Rak*_*ala 5 flask angularjs angularjs-directive
我在客户端使用flask作为后端和angularjs
我的目录结构:
露:
->app.py
->templates
->hello.html
->test.html
->static
->js
->directives.py
->lib
->angular.js
Run Code Online (Sandbox Code Playgroud)
我的app.py文件:
from flask import Flask, make_response,render_template
@app.route("/aboutUs")
def aboutUs():
return render_template("test.html", title="test page")
Run Code Online (Sandbox Code Playgroud)
我的directives.py文件:
angular.module('components',[])
.directive("helloWorld",function($scope,$log){
$scope.$log = $log;
return{
restrict:"A",
templateUrl:"templates/hello.html"
}
})
angular.module('testApp',['components'])
Run Code Online (Sandbox Code Playgroud)
Flask能够正确渲染test.html模板,但angular显示了hello.html,找不到模板错误
如果hello.html包含Jinja2标记,则它是一个模板,需要由Flask呈现.添加一个@app.route来渲染它.
@app.route("/hello")
def hello():
return render_template("hello.html")
Run Code Online (Sandbox Code Playgroud)
然后指向helloAngular指令中的URL.
templateUrl: "{{ url_for('hello'}} }}"
Run Code Online (Sandbox Code Playgroud)
如果文件只包含HTML(没有Jinja2标记),那么它不是模板.它不应该在templates文件夹中,而应该在静态文件夹中 ; 喜欢static/angular_templates/hello.html.
然后指向指令中的静态文件.
templateUrl: "{{ url_for('static', filename='angular_templates/hello.html') }}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2119 次 |
| 最近记录: |