python flask api get request code example
Example 1: python flask rest api
from flask import Flask
from flask_restful import Resource, Api
app = Flask(__name__)
api = Api(app)
class HelloWorld(Resource):
def get(self):
return {'hello': 'world'}
api.add_resource(HelloWorld, '/')
if __name__ == '__main__':
app.run(debug=True)
Example 2: get requests method flask
import flask
app = flask.Flask('your_flask_env')
@app.route('/register', methods=['GET', 'POST'])
def register():
if flask.request.method == 'POST':
username = flask.request.values.get('user') # Your form's
password = flask.request.values.get('pass') # input names
your_register_routine(username, password)
else:
# You probably don't have args at this route with GET
# method, but if you do, you can access them like so:
yourarg = flask.request.args.get('argname')
your_register_template_rendering(yourarg)