Skip to content

Instantly share code, notes, and snippets.

@loelkes
Created April 6, 2019 09:28
Show Gist options
  • Save loelkes/80a35c1f7dee2d02ca27dcbc61076e1b to your computer and use it in GitHub Desktop.
Save loelkes/80a35c1f7dee2d02ca27dcbc61076e1b to your computer and use it in GitHub Desktop.
JugendHackt Flask template
# First install necessary packages
# pip install flask
# Import the modules
from flask import Flask, jsonify, request
# create the app. This variable named jh constains our app
jh = Flask(__name__)
data = dict(name='cities', data=['Delhi', 'Mumbai', 'Hyderabad'])
# add routes to our app
@jh.route('/')
def hello_world():
return 'Hello, World!'
@jh.route('/cities')
def cities():
return jsonify(data)
@jh.route('/city/add')
def add_city():
args = request.args.to_dict()
name = args['name']
if len(name) < 3:
return jsonify(dict(status=False, message='Too short'))
else:
data['data'].append(name)
return 'Added city {}'.format(name)
# This comment a comment
# Run the app if someone runs this file.
if __name__ == "__main__":
jh.run(debug=True)
# to run call: python filename.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment