好的,所以我在服务器端有这段代码:
@app.route('/physical_graph')
@login_required
def physical_graph():
# Some code
return generate_graph_view()
如果我们点击圆形图标,我们将获得链接 /physical_graph#physical.circular:
<a class="icon" href="/physical_graph#physical.circular">
<img src="{{url_for('static',filename='images/circular64x64.png')}}"
id="circular_icon" width="32" height="32" title="Circular layout"/>
</a>
我的问题是:如何告诉 Flask 散列后的字符串是什么?我需要这个,因为注释中的代码取决于这个字符串。我尝试将 app.route 声明为:
@app.route('/physical_graph#<some_string>')
但没有成功 - 它给我错误 404。
有什么办法吗?
最佳答案
当你对它进行 ajax 化时,你需要将 physical.circle 传递给服务器。首先是对 icon:
<!-- notice i change from icon -> graphIcon icon is too general -->
<!--a stylist would be angry at you for using icon -->
<a class="graphIcon" href="/physical_graph#physical.circular"> .. </a>
你有一些选择首先是将它传递到数据属性中,这将被放置在 javascript 中的某个地方(只执行一次)。
jQuery("#circular_icon").click(function() {
$.ajax({
url:'/physical_graph',
data:{
'graph_type': 'physical_graph.circular'
},
'success':function(data){
//your function goes here.
}
})
} );
@app.route('/physical_graph')
@login_required
def physical_graph():
_type = request.args.get('graph_type')
关于javascript - Flask 中的动态散列链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15616504/