使用python函数在flask中链接url

2024-05-23 22:55:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Flask中链接一个url,但找不到解决问题的方法。我的想法是根据我网页上给出的参数在UniProt中搜索一种蛋白质。例如:

@app.route('/http.html')
def http():
    return render_template('http.html')

@app.route('/http_results', methods=['POST'])
def http_results():
    protname_seq = request.form['protname_seq']
    specie_seq = request.form['specie_seq']
    input_text = seqtools.httplink(protname_seq,specie_seq)
    return render_template('http_results.html', **locals())

seqtools中,我有一个python代码,它具有以下函数:

^{pr2}$

而现在在http_results.html我尝试了多种方法,但最终结果是None或者是一个错误,所以我真的不知道如何继续。http_results.html代码是:

^{3}$

只想知道链接到UniProt网页的蛋白质名称。谢谢你的帮助,对不起我的英语。在


Tags: 方法apphttp网页return链接defhtml
2条回答

print函数返回None,因此,您需要将print和赋值操作分成两行:

c='http://www.uniprot.org/uniprot/?query='+a+b+'&sort=score'
print(c)
return c

另外,您需要在a标记中的href加引号:

^{pr2}$

在名为httplink的函数中,您不分配c任何内容。您应该在print语句中返回字符串文本。在

def httplink(prot, specie):
    url = 'http://www.uniprot.org/uniprot/?query=%s_%s&sort=score'
    return url % (prot, specie)

这个功能应该可以解决这个问题。在

相关问题 更多 >