Last active
December 26, 2020 02:31
-
-
Save HH0718/446ac3cbc6d83e4d99be11977bbb87e2 to your computer and use it in GitHub Desktop.
My attempt to help out /u/PepeTheMule on reddit post: https://www.reddit.com/r/learnpython/comments/kk4kab/flask_question_in_regards_to_get_and_post_within/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, render_template, jsonify | |
import sys | |
app = Flask(__name__) | |
@app.route('/renewapikey', methods=['POST', 'GET']) | |
def renew_api_key(): | |
data = (request.form.to_dict()) | |
print(data, sys.stderr) | |
if request.method == 'GET': | |
print('GET request made') | |
return render_template('renewapikey.html') | |
if request.method == 'POST': | |
print('POST request made') | |
return jsonify( | |
{"first_name": data['fname'], "last_name": data['lname']}) # return the new API KEY or whatever you needed. | |
if __name__ == '__main__': | |
app.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<h1>Current API Key: current_user.apikey</h1> | |
<form action="/renewapikey" method="POST"> | |
<label for="fname">First name:</label> | |
<input type="text" id="fname" name="fname"><br><br> | |
<label for="lname">Last name:</label> | |
<input type="text" id="lname" name="lname"><br><br> | |
<input type="submit" name="submit_button" value='Submit'> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment