python - 从烧瓶函数获取返回值到另一个 python 文件(从非烧瓶 python 文件调用烧瓶函数)
问题描述
我必须从 python 的网页中获取输入。我为此使用烧瓶。我想返回它得到的输入。我想将该flask函数调用到另一个不使用flask的文件中,只是python文件。示例:以下代码在 inputpage.py 中
@app.route('/topic', methods=['GET', 'POST'])
def topic_input():
res = None
if request.method == 'POST':
if not request.form['t1'] and not request.form['t2'] :
res = 'please fil the form'
# print(result)
else:
try:
term = request.form['t1']
t2 = int(request.form['t2'])
res='Good'
except BaseException as error:
res = 'error: {}'.format(error)
# print(result)
#return render_template('topic.html', articles=res_dic, result=res)
return(term,t2)
在另一个文件中说 test.py 我尝试调用上述函数,
from inputpage import topic
print(topic_input())
但我收到以下错误:raise RuntimeError(_request_ctx_err_msg) RuntimeError: Working outside of request context。
这通常意味着您尝试使用需要活动 HTTP 请求的功能。有关如何避免此问题的信息,请参阅有关测试的文档。
我想知道我怎么能做这样的事情。感谢您的帮助:)
解决方案
推荐阅读
- oracle - Is Oracle Database Supported in Joomla?
- c# - Building a block user functionality: how to force user to logout or terminate their existing session
- r - 当列名有空格时,以编程方式从数据框中选择列
- swift - Splitting up Firebase Snapshots into smaller pieces?
- vuejs2 - Vuex 更新后强制 props 在子组件中更新
- oracle - 将oracle中的负数转换为十六进制会给出错误的输出?
- redux - Redux Toolkit - 将整个数组分配给状态
- pandas - 有没有办法在熊猫中重新安排两个数据集?
- javascript - react-router-dom:历史不会自动重新加载(渲染)页面
- python - 如何拆分包含空格的合并列