Issue
currently i have a Problem, where i send a POST Request but request.method returns 'GET'. any idea?
my Code:
@app.route('/login1', methods=['POST', 'GET'])
def login1():
print(request.method)
print(request.form)
print(request.values)
print(request.get_data())
print(request.get_json())
if request.method == 'POST':
print("POST!!!")
print(request)
return str(request.is_json)```
JSON:
{
"username": "[email protected]",
"password": "test"
}
Solution
I assume, that you submit a form before you check if there was any request. If not try this:
1. Create a form
<form method="post">
<input type="text" name="username">
<input type="submit value="Login">
</form>
2. Check for any request
from flask import Flask, request
@app.route('/login1', methods=['POST', 'GET'])
def login1():
if request.method == 'POST:
# do something
You can also make a request via a button, a hyperlink and various other html objects. Sheers!
Answered By - M Λ I K
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.