在使用flask-restfull進(jìn)行API開發(fā)的時候。一旦我使用類似下面的代碼從url或者form中獲得參數(shù)就會出現(xiàn)報錯:Did not attempt to load JSON data because the request Content-Type was not ‘a(chǎn)pplication/json’。
代碼如下:文章來源:http://www.zghlxwxcb.cn/news/detail-594846.html
from flask_restful import reqparse
parser = reqparse.RequestParser()
parser.add_argument("page", type=int)
parser.add_argument("limit", type=int)
class IndustryListResource(Resource):
def get(self):
args = parser.get_page_parser()
records = Industry.query.order_by(Industry.id).all()
return Result.list_result(records)
解決方法如下文章來源地址http://www.zghlxwxcb.cn/news/detail-594846.html
# 增加location的來源
parser.add_argument("page", type=int, location="args")
到了這里,關(guān)于Did not attempt to load JSON data because the request Content-Type was not ‘a(chǎn)pplication/json‘的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!