代码如下
from flask import Flask
app=Flask(__name__)
@app.route("/",mehtods=["GET"])
def index():
return "",200
if __name__=="__main__":
app.run()
运行报错
Traceback (most recent call last):
File "b.py", line 7, in <module>
@app.route("/",mehtods=["GET"])
File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/flask/scaffold.py", line 435, in decorator
self.add_url_rule(rule, endpoint, f, **options)
File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/flask/scaffold.py", line 56, in wrapper_func
return f(self, *args, **kwargs)
File "/Users/jiangyd/PycharmProjects/untitled16/venv/lib/python3.7/site-packages/flask/app.py", line 1085, in add_url_rule
rule = self.url_rule_class(rule, methods=methods, **options)
TypeError: __init__() got an unexpected keyword argument 'mehtods'
关键字写错了,这个是比较容易犯的错误,但是根据错误,却是可以容易解决
from flask import Flask
app=Flask(__name__)
@app.route("/",methods=["GET"])
def index():
return "",200
if __name__=="__main__":
app.run()
您好,关键字写错了,请参考如下示例:
@app.route('/login/',methods=['GET','POST'])
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。