Skip to content

Instantly share code, notes, and snippets.

@Whistler092
Created July 13, 2017 00:49
Show Gist options
  • Save Whistler092/6487344efefa1b4b6b32e05f5c5715b5 to your computer and use it in GitHub Desktop.
Save Whistler092/6487344efefa1b4b6b32e05f5c5715b5 to your computer and use it in GitHub Desktop.
talk flask api
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# dotenv
.env
# virtualenv
.venv
venv/
env3/
ENV/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
#Visual Studio Code
.vscode/
#Pycharm
.idea/

talk_flask

charla introductoria de flask

    pip install virtualenv
    virtualenv -p python3.6 env3
    source env3/bin/activate
    pip install flask
        pip install -r requirements.txt
    python run.py
from flask import Flask, jsonify, abort
app = Flask(__name__)
songs = [
{
'name': 'Lake Sprinkle Sprankle',
'band': 'Delta Sleep',
'album': 'Twin Galaxies',
'release': 2015
},
{
'name': 'Back to the old',
'band': 'Matisyahu',
'album': 'Undercurrent',
'release': 2017
},
{
'name': 'Perfect Pillow',
'band': 'Chon',
'album': 'Grow',
'release': 2016
}
]
@app.route("/<int:index>")
def get_song(index):
try:
song = songs[index]
except IndexError:
abort(404)
return jsonify(song)
if __name__ == "__main__":
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment