[英]2 way to call a resource in Flask-Restful?
I'm learning and using Python, Flask and Flask-Restful for traineeship and I got a question : 我正在学习并使用Python,Flask和Flask-Restful进行实习,但我遇到了一个问题:
Right now I've something like this 现在我有这样的事情
class CheckTXT(Resource):
def get(self):
import dns.resolver
dmn = request.args.get('dmn')
answers = dns.resolver.query(dmn, 'TXT')
c = []
for rdata in answers:
for txt_string in rdata.strings:
c.append(txt_info(dmn, txt_string))
end = time.time()
tm = end - start
return lookup("TXT", dmn, c, tm)
and 和
api.add_resource(CheckTXT, '/lookup/txt')
I'd like to call it by 2 way : 我想用两种方式称呼它:
lookup/txt?dmn=stackoverflow.com
/lookup/txt/stackoverflow.com
The first one is working but I don't know how to do the second or even if it's possible. 第一个正在工作,但是我不知道如何做第二个,即使可能的话。
Someone can help me ? 有人可以帮助我吗? Thanks for your attention and your patience !
感谢您的关注和耐心等待! You're helping a young padawan ahah
你在帮一个年轻的padawan啊
Yes you can use below as endpoint and possible with flask resful 是的,您可以在下面用作端点,并可能在烧瓶稳定时使用
/lookup/txt/stackoverflow.com
for that you need to add resources like 为此,您需要添加资源,例如
api.add_resource(CheckTXT, '/lookup/txt/<string:name>')
and you can access that field in your implementation like below api.add_resource(CheckTXT, '/lookup/txt/<string:name>')
,您可以像下面这样在实现中访问该字段
class CheckTXT(Resource):
def get(self,name):
print name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.