angularjs找不到模板目录,flask作为后端
我使用flask作为后端,在客户端使用angularjs 我的目录结构: 露水:angularjs找不到模板目录,flask作为后端,angularjs,flask,angularjs-directive,Angularjs,Flask,Angularjs Directive,我使用flask作为后端,在客户端使用angularjs 我的目录结构: 露水: ->app.py ->templates ->hello.html ->test.html ->static ->js ->directives.py ->lib ->angular.js my app.py文件: from flask import Flask, make_respons
->app.py
->templates
->hello.html
->test.html
->static
->js
->directives.py
->lib
->angular.js
my app.py文件:
from flask import Flask, make_response,render_template
@app.route("/aboutUs")
def aboutUs():
return render_template("test.html", title="test page")
my directions.py文件:
angular.module('components',[])
.directive("helloWorld",function($scope,$log){
$scope.$log = $log;
return{
restrict:"A",
templateUrl:"templates/hello.html"
}
})
angular.module('testApp',['components'])
Flask能够正确呈现test.html模板,但angular显示hello.html,template not found错误1。金贾模板
如果hello.html
包含Jinja2标记,则它是一个模板,需要由Flask呈现。添加一个@app.route
来渲染它
@app.route("/hello")
def hello():
return render_template("hello.html")
然后指向Angular指令中的hello
URL
templateUrl: "{{ url_for('hello'}} }}"
templateUrl: "{{ url_for('static', filename='angular_templates/hello.html') }}"
2.角模板
如果文件仅包含HTML(无Jinja2标记),则它不是模板。它不应位于模板
文件夹中,而应位于静态文件夹中;比如静态/角度模板/hello.html
然后指向指令中的静态文件
templateUrl: "{{ url_for('hello'}} }}"
templateUrl: "{{ url_for('static', filename='angular_templates/hello.html') }}"