【发布时间】:2020-03-15 14:39:54
【问题描述】:
我确定在某处可能存在此问题的重复项,但我不知道我的问题的正确措辞是什么。
我有想要到达的端点,我在它们上运行了curl 命令:
curl http://0.0.0.0:5001/job/task/?job_type=medicine&task_type=research
curl http://0.0.0.0:5001/job/task/?job_type=medicine&task_type=research&job_id=123
我得到的两个错误是:
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
我的部分代码如下所示,我感觉这与我使用api.add_resource的方式有关:
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class Test(Resource):
def get(self,job_type,task_type,task_id = None):
if not task_id:
return {"job_type":job_type,"task_type":task_type}
return {"job_type":job_type,"task_type":task_type,"job_id":job_id}
api.add_resource(Test, '/job/task/?<string:job_type>&<string:task_type>', '/job/task/?<string:job_type>&<string:task_type>&<int:job_id>')
我该如何解决这个错误?
【问题讨论】:
标签: python flask flask-restful