gpt4 book ai didi

javascript - flask + AngularJS : ng-include is 404'ing

转载 作者:行者123 更新时间:2023-12-02 17:16:37 25 4
gpt4 key购买 nike

我一直在疯狂地尝试让 angularjs 的 ng-include 与 Flask 应用程序一起正常工作,似乎无论我尝试什么,GET 都会返回 404。主页(angular_test.html)加载正常,但 angular_entry.html 没有加载任何内容。

flask :

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?是我的应用程序根路径设置不正确还是什么?

救命!

最佳答案

如果不知道 c 是什么或者它的 get 方法做什么,就不可能完全判断出来,但最有可能的是您错误地使用了 flask.Blueprint 的 >templates 参数。如果您想将模板公开给 Angular,则需要可以通过 HTTP 访问它们。 Flask 的模板通过 render_template 通过服务器端的 Jinja 模板引擎提供,并且不会通过 HTTP 直接向最终用户公开。

如果这是问题所在,您需要将 angulartemplates 移动到 static 下,并更改包含路径以正确引用 /static/angularetemplates/{your_template_name} (您还可以在 Blueprint 初始值设定项中删除关键字参数 templates)。

关于javascript - flask + AngularJS : ng-include is 404'ing,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24391129/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com