【发布时间】:2014-06-24 15:52:11
【问题描述】:
我一直在疯狂地尝试让 angularjs 的 ng-include 与 Flask 应用程序一起正常工作,似乎无论我尝试什么,GET 都会不断返回 404'd。主页 (angular_test.html) 加载正常,但 angular_entry.html 没有。
烧瓶:
basedir = c.get('basedir')
app = Blueprint('angulartest', __name__, static_folder=basedir+'/display/static',
template_folder=basedir+'/display/angulartemplates')
def before_blueprint_request():
g.user = current_user
app.before_request(before_blueprint_request)
@app.route('/angular_test.html', methods=['GET'])
def ang_test():
print 'testing angular'
return make_response(open(basedir+'/display/templates/angular_test.html').read())
#
# return app.send_static_file('angular_test.html') (I've tried both)
HTML:
<div id='content' ng-app='FeedEaterApp' ng-controller='MainController'>
<select ng-model="template" ng-options="t.name for t in templates">
<option value="">(blank)</option>
</select>
url of the template: <tt>{{template.url}}</tt>
<div ng-include src="'angular_entry.html'"></div>
<div ng-include src="template.url"></div>
<div ng-include="'angular_entry.html'"></div>
<div ng-include="template.url"></div>
</div>
JS:
app.controller("MainController", function($scope){
$scope.message = 'this is a message from scope!~'
$scope.templates =
[ { name: 'template1.html', url: 'angular_entry.html'},
{ name: 'template2.html', url: 'template2.html'} ];
$scope.template = $scope.templates[0];
});
我还尝试了我能想到的每一个相对/绝对路径,但仍然只有 404。我也尝试过改变 Flask 中的静态和模板文件夹。没有骰子。
Flask 会干扰 angular_entry.html 上的 GET 吗?是我的应用程序根路径设置不正确还是什么?
帮助!
【问题讨论】:
标签: javascript python angularjs flask angularjs-ng-include