Skip to content

Instantly share code, notes, and snippets.

@Sanix-Darker
Last active March 24, 2020 10:42
Show Gist options
  • Save Sanix-Darker/ad1c71016de5d01e73db8decfcffd259 to your computer and use it in GitHub Desktop.
Save Sanix-Darker/ad1c71016de5d01e73db8decfcffd259 to your computer and use it in GitHub Desktop.
[PYTHON]SIMPLE PYTHON FLASK STARTER

SIMPLE AND BASIC REST PYTHON FLASK STARTER

How to install

pip install -r requirements.txt

How to launch

python SIMPLE_PYTHON_FLASK_STARTER.py

Author

  • Sanix darker
flask>=0.12.3
flask-cors==3.0.3
# coding: utf-8
from flask import Flask, jsonify, request
from flask_cors import CORS, cross_origin
app = Flask(__name__)
CORS(app, support_credentials=True)
app.config['Secret'] = "Secret"
@app.route('/', methods=['GET']) # To prevent Cors issues
@cross_origin(supports_credentials=True)
def index():
# Sent in GET requests
param = request.args.get('param')
# Build the response
response = jsonify({ 'status':'success', 'message': 'Welcome to flask API.' })
# Let's allow all Origin requests
response.headers.add('Access-Control-Allow-Origin', '*') # To prevent Cors issues
return response
if __name__ == "__main__":
app.run(host='0.0.0.0', debug=True, port=7777)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment