【发布时间】:2017-07-18 04:06:15
【问题描述】:
我在 Python3 中使用 POST 方法编写了一个 Flask 应用程序。每当我点击 URL 时,在命令提示符下,我都会看到 GET 方法被调用。
这是应用程序:
from flask import Flask, jsonify, make_response, request
app = Flask(__name__)
@app.route('/api/v1.0/qanda/', methods=['POST'])
def people_api():
if request.method == 'POST':
text = request.data.get('text', '')
if text is None:
make_response(jsonify({'error': 'Missing text parameter'}), 400)
return text
app.run()
每当我点击网址时:
http://127.0.0.1:5000/api/v1.0/qanda/?text=ggg
我在命令行中看到的是:
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [18/Jul/2017 09:33:15] "GET /api/v1.0/qanda/?text=ggg HTTP/1.1" 200 -
127.0.0.1 - - [18/Jul/2017 09:33:22] "GET /api/v1.0/qanda/?text=ggg HTTP/1.1" 200 -
但我只想在点击 URL 时使用 post 方法。我不知道为什么 GET 方法正在发挥作用。请告诉我如何在通过浏览器访问 URL 时使用 POST 方法而不是 GET 方法。
【问题讨论】:
-
用于创建 post 请求的 Chrome 插件(以及许多其他插件,例如 Postman)很不错。
<form method="post" ... >的 html 表单也可以使用 -
通过浏览器点击 URL 时,它总是会通过浏览器向您的服务器发送 GET 请求。你不可能通过这种方式发送 POST 请求!
标签: python python-3.x flask http-post flash-message