Python framework bottle notes

Introduction

bottle is a lightweight framework for python. The main body seems to be only one file. If you google, many articles in Japanese will appear, so I will omit the details.

http://bottlepy.org/docs/dev/index.html

It will be updated gradually.

Environment

My machine

OS X Yosemite Ver 10.10.5

Install python (2.7.10)

reference

http://qiita.com/zaburo/items/fbdaf6c04151671407db http://qiita.com/zaburo/items/802423b0d2d63b0cb456

Implementation

brew edit python

url "https://www.python.org/ftp/python/2.7.11/Python-2.7.11.tgz"
sha256 "82929b96fd6afc8da838b149107078c02fa1744b7e60999a8babbc0d3fa86fc6"
sha256 "e22a23bec350c287ddcc1d48b1a58b2b27a8d19e79837fa684e71c2eb7ea6456" => :yosemite

Corrected the above part to ↓↓↓

url "https://www.python.org/ftp/python/2.7.10/Python-2.7.10.tgz"
sha256 "eda8ce6eec03e74991abb5384170e7c65fcd7522e409b8e83d7e6372add0f12a"
sha256 "726e13ae4d0befdc86ae82c1585393de814609d8f6b2fda5ef2be8514f654c4d" => :yosemite
brew install python
abridgement

which python
/usr/local/bin/python
pip2.7 install --upgrade pip
pip2.7 install --upgrade setuptools
pip2.7 install matplotlib
Collecting matplotlib
  Downloading matplotlib-1.5.1-cp27-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (49.7MB)
    100% |████████████████████████████████| 49.7MB 18kB/s
Collecting numpy>=1.6 (from matplotlib)
  Downloading numpy-1.11.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (3.9MB)
    100% |████████████████████████████████| 3.9MB 227kB/s
Collecting pytz (from matplotlib)
  Downloading pytz-2016.4-py2.py3-none-any.whl (480kB)
    100% |████████████████████████████████| 481kB 841kB/s
Collecting python-dateutil (from matplotlib)
  Downloading python_dateutil-2.5.3-py2.py3-none-any.whl (201kB)
    100% |████████████████████████████████| 204kB 576kB/s
Collecting cycler (from matplotlib)
  Downloading cycler-0.10.0-py2.py3-none-any.whl
Collecting pyparsing!=2.0.0,!=2.0.4,>=1.5.6 (from matplotlib)
  Downloading pyparsing-2.1.1-py2.py3-none-any.whl
Collecting six>=1.5 (from python-dateutil->matplotlib)
  Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: numpy, pytz, six, python-dateutil, cycler, pyparsing, matplotlib
Successfully installed cycler-0.10.0 matplotlib-1.5.1 numpy-1.11.0 pyparsing-2.1.1 python-dateutil-2.5.3 pytz-2016.4 six-1.10.0


pip2.7 install pillow

Bottle environment construction

pip2.7 install bottle

/path/to/bottle/app/main.py


from bottle import route, run, static_file, url
from top import index

@route('/static/<filepath:path>')
def static(filepath):
    return static_file(filepath, root="./static")

@route('/')
def top():
    return index(url)

run(host='localhost', port=8080, debug=True, reloader=True)

/path/to/bottle/app/top.py


from bottle import template, view
import const

@view("index")
def index(url):
    return dict(url=url, design_path=const.DESIGN_PATH)

/path/to/bottle/app/const.py


DESIGN_PATH = './static/startbootstrap-sb-admin-2-1.0.8'

python main.py
http://localhost:8080/

Directory structure

myapp
    ├── const.py        //Constant
    ├── main.py         //routing
    ├── static          //Set up static files
    │ ├─ css            //Example: putting css
    │ ├─ js             //Example: putting js
    │ └─ img            //Example: Putting an image
    ├── top.py          //Top screen processing
    └── views           //Template storage
        └── index.tpl   //Top screen template

Function memo

others

/usr/local/lib/python2.7/site-packages/

Recommended Posts

Python framework bottle notes
Python scraping notes
Python study notes _000
Python learning notes
Python beginner notes
Python study notes_006
python C ++ notes
Python study notes _005
Python grammar notes
Python Library notes
python personal notes
python pandas notes
Python study notes_001
python learning notes
Python3.4 installation notes
Django python web framework
Python package development notes
python decorator usage notes
Python ipaddress package notes
[Personal notes] Python, Django
Python Pickle format notes
Python AI framework summary
[Python] pytest-mock Usage notes
First Python miscellaneous notes
Matlab => Python migration notes
Framework development in Python
Notes using Python subprocesses
Knowledge notes needed to understand the Python framework
Python try / except notes
Python notes using perl-ternary operator
python3: How to use bottle (2)
O'Reilly python3 Primer Learning Notes
Web scraping notes in python3
BASIC authentication with Python bottle
Python standard unittest usage notes
python * args, ** kwargs Usage notes
Python notes using perl-special variables
Python Tkinter notes (for myself)
[Python] Notes on data analysis
Python data analysis learning notes
Notes on installing Python on Mac
Get Evernote notes in Python
Notes on installing Python on CentOS
python3: How to use bottle (3)
python3: How to use bottle
Notes on Python and dictionary types
Minimum grammar notes for writing Python
Implemented file download with Python + Bottle
Notes on using MeCab from Python
Personal notes for python image processing
Python Pandas Data Preprocessing Personal Notes
Typing automation notes by Python beginners
Notes for me python csv graph
Notes on installing Python using PyEnv
Create a Python general-purpose decorator framework
Notes for Python file input / output
Notes on using rstrip with python.
Notes on accessing dashDB from python
I made a scaffolding tool for the Python web framework Bottle
Install Python framework django using pip
(Personal notes) Python metaclasses and metaprogramming