在烧瓶中返回HTTP状态代码201 [英] Return HTTP status code 201 in flask

查看:231
本文介绍了在烧瓶中返回HTTP状态代码201的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Flask作为我们的API之一,我只是想知道是否有人知道如何返回HTTP响应201?



对于像404这样的错误,可以调用:

  from flask import abort 
abort(404)

但是对于201,我得到了

lockquote

LookupError: 201


我是否需要创建自己的异常,如这个在文档?

解决方案

here。

  return render_template('page.html'),201 


We're using Flask for one of our API's and I was just wondering if anyone knew how to return a HTTP response 201?

For errors such as 404 we can call:

from flask import abort
abort(404)

But for 201 I get

LookupError: no exception for 201

Do I need to create my own exception like this in the docs?

解决方案

You can read about it here.

return render_template('page.html'), 201

这篇关于在烧瓶中返回HTTP状态代码201的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆