Skip to content

Instantly share code, notes, and snippets.

@HH0718
Last active December 26, 2020 02:31
Show Gist options
  • Save HH0718/446ac3cbc6d83e4d99be11977bbb87e2 to your computer and use it in GitHub Desktop.
Save HH0718/446ac3cbc6d83e4d99be11977bbb87e2 to your computer and use it in GitHub Desktop.
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()
<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