将 python 代码链接到 FLASK
Linking python code to FLASK
一个 link 如何在 flask 中使用独立的 python 代码。
示例。
import sys
# By design, the patterns come in one per line piped in from STDIN
for line in sys.stdin.readlines():
line = line.strip()
# 1) Split the pattern into clauses.
# 2) Translate each clause into regex syntax
# 3) reassemble the full regex pattern
clauses = line.split("-")
regex_clause_array = []
for clause in clauses:
# re_clause: the incremental build-up of the clause into regex syntax
re_clause=None
# Convert the prosite negation into a regex inverted character class
if clause.startswith("{"):
neg_pieces = clause.split("}")
# neg_pieces[0][1:] is the character set for the negation
# neg_pieces[1] is the optional quantification
re_clause = "[^%s]%s" % (neg_pieces[0][1:], neg_pieces[1])
else:
re_clause = clause
# change the quantification parenthesis into regex curly-braces
re_clause = re_clause.replace(")","}")
re_clause = re_clause.replace("(","{")
# change wildcards from 'x' to '.'
re_clause = re_clause.replace("x",".")
# save the regex-syntax clause to the regex clause array
regex_clause_array.append(re_clause)
# add the leading and trailing slashes and concatenate all regex clauses
# together to form the full regex pattern
print ("/%s/" % ("".join(regex_clause_array)))
上面的代码是独立运行的,它采用一个序列,例如 P-x(2)-G-E-S-G(2)-[AS] 并转换为 python 正则表达式 P。{2}GESG{2} [AS].
我想不通的是,我正在尝试使用 flask 将其 link 放入 webtool 中。我现在拥有的是一个简单的网页,它有一个文本框和一个提交按钮,但无法 link 上面的代码到路由应用程序。
将代码放在不同的 python 文件中并命名。现在,您可以将 python 文件用作模块。将代码放在一个函数中。您可以在 flask 中导入 python 文件。
from filename import function
您可以在像
这样的视图中使用它
@app.route('/link' , methods = ['POST'])
def view_function():
call = function()
现在在提交按钮中你可以这样做:
<form action="/link" method = 'post'>
<input type="submit" value="submit" />
</form>
一个 link 如何在 flask 中使用独立的 python 代码。
示例。
import sys
# By design, the patterns come in one per line piped in from STDIN
for line in sys.stdin.readlines():
line = line.strip()
# 1) Split the pattern into clauses.
# 2) Translate each clause into regex syntax
# 3) reassemble the full regex pattern
clauses = line.split("-")
regex_clause_array = []
for clause in clauses:
# re_clause: the incremental build-up of the clause into regex syntax
re_clause=None
# Convert the prosite negation into a regex inverted character class
if clause.startswith("{"):
neg_pieces = clause.split("}")
# neg_pieces[0][1:] is the character set for the negation
# neg_pieces[1] is the optional quantification
re_clause = "[^%s]%s" % (neg_pieces[0][1:], neg_pieces[1])
else:
re_clause = clause
# change the quantification parenthesis into regex curly-braces
re_clause = re_clause.replace(")","}")
re_clause = re_clause.replace("(","{")
# change wildcards from 'x' to '.'
re_clause = re_clause.replace("x",".")
# save the regex-syntax clause to the regex clause array
regex_clause_array.append(re_clause)
# add the leading and trailing slashes and concatenate all regex clauses
# together to form the full regex pattern
print ("/%s/" % ("".join(regex_clause_array)))
上面的代码是独立运行的,它采用一个序列,例如 P-x(2)-G-E-S-G(2)-[AS] 并转换为 python 正则表达式 P。{2}GESG{2} [AS].
我想不通的是,我正在尝试使用 flask 将其 link 放入 webtool 中。我现在拥有的是一个简单的网页,它有一个文本框和一个提交按钮,但无法 link 上面的代码到路由应用程序。
将代码放在不同的 python 文件中并命名。现在,您可以将 python 文件用作模块。将代码放在一个函数中。您可以在 flask 中导入 python 文件。
from filename import function
您可以在像
这样的视图中使用它@app.route('/link' , methods = ['POST'])
def view_function():
call = function()
现在在提交按钮中你可以这样做:
<form action="/link" method = 'post'>
<input type="submit" value="submit" />
</form>