Make the pip command available.
$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
$ python get-pip.py --user
$ pwd /home/users/0/sub.jp-hrd
Edit .bash_profile $vi .bash_profile
PATH=$PATH:/home/users/0/sub.jp-hrd/.local/bin export PATH
$ source .bash_prof
With this work, you can use pip etc.
pip install bottle --user
####When installing with pip--If you add the user option, it will be installed in the user directory.
$ pip freeze DEPRECATION: Python 3.4 support has been deprecated. pip 19.1 will be the last one supporting it. Please upgrade your Python as Python 3.4 won't be maintained after March 2019 (cf PEP 429). Beaker==1.10.0 bottle==0.12.13 bottle-auth==0.3.3 bottle-beaker==0.1.3 bottle-mongo==0.3.0 bottle-sqlite==0.1.3 certifi==2019.9.11
###python on cheap server of lolipop/Mod to work Bottle_Since wsgi cannot be used, some ingenuity is required.
##List of folder paths
W3
│ .htaccess
└─app
│ .htaccess
│ app.py
│ routes.py
│
├─static
│ ├─content
│ │ bootstrap-grid.css
│ │ bootstrap-grid.css.map
│ │ bootstrap-grid.min.css
│ │ bootstrap-grid.min.css.map
│ │ bootstrap-reboot.css
│ │ bootstrap-reboot.css.map
│ │ bootstrap-reboot.min.css
│ │ bootstrap-reboot.min.css.map
│ │ bootstrap.css
│ │ bootstrap.css.map
│ │ bootstrap.min.css
│ │ bootstrap.min.css.map
│ │ jumbotron.css
│ │ site.css
│ ├─fonts
│ │ glyphicons-halflings-regular.eot
│ │ glyphicons-halflings-regular.svg
│ │ glyphicons-halflings-regular.ttf
│ │ glyphicons-halflings-regular.woff
│ └─scripts
│ bootstrap.bundle.js
│ bootstrap.bundle.js.map
│ bootstrap.bundle.min.js
│ bootstrap.bundle.min.js.map
│ bootstrap.js
│ bootstrap.js.map
│ bootstrap.min.js
│ bootstrap.min.js.map
│ jquery-1.10.2.intellisense.js
│ jquery-1.10.2.js
│ jquery-1.10.2.min.js
│ jquery-1.10.2.min.map
│ jquery.validate-vsdoc.js
│ jquery.validate.js
│ jquery.validate.min.js
│ jquery.validate.unobtrusive.js
│ jquery.validate.unobtrusive.min.js
│ modernizr-2.6.2.js
│ respond.js
│ respond.min.js
│ _references.js
├─views
│ about.tpl
│ contact.tpl
│ home.tpl
│ index.tpl
│ layout.tpl
Assuming that the w3 directory is the root of the web, it was placed directly under it..htaccess is as follows.
#### **` .htaccess`**
```htaccess
RewriteEngine on
RewriteRule ^(.*).py$ https://w3.hrd.co.jp/app/$1
RewriteRule ^(.*)$ https://w3.hrd.co.jp/app/app.py/$1
DirectoryIndex app.py
abovehttps://w3.hrd.co.jp
Please change to your domain.
This notation rewrites the sweb server url.
RewriteRule ^(.*).py$ https://w3.hrd.co.jp/app/$1
https://w3.hrd.co.When jp is requestedhttps://w3.hrd.co.jp/app/app.py
Rewrite to.
app.py goes into the web server event loop so app.You have to access views etc. to the directory directly under py. It will be realized below.
RewriteRule ^(.*)$ https://w3.hrd.co.jp/app/app.py/$1
app.py just defines routes.
#### **`app.py`**
```py
!/usr/local/bin/python3.4
-*- coding: utf-8 -*-
from bottle import *
import routes
run(server='cgi')
!/usr/local/bin/python3.4
-*- coding: utf-8 -*-
from bottle import *
from datetime import datetime
import requests
js = [('coffee','coffee'), ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4 '), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9 '), ('10', '10'), ('11', '11'), ('12', '12'), ('TV','TV'), ('cup','CH + '), ('cdwn','CH-'), ('vup','Vol +'), ('vdwn','Vol-'), ('vcut','Mute'), ('bs', 'bs'), ('cs','cs'), ('bs1','bs1'), ('bs2','bs2'), ('bs3','bs3'), ('bs4', 'bs4'), ('bs5','bs5'), ('bs6','bs6'), ('bs7','bs7'), ('bs8','bs8'), ('bs9', 'bs9'), ('bs10','bs10'), ('bs11','bs11'), ('bs12','bs12'), ('inUp','inUp'), ('inDwn', 'inDwn'), ('ent','ent'), ('on','all lights'), ('off','off'), ('fav','favorite'), ('small' ',' Security Light'), ('lup','Ming'), ('ldwn','Dark'), ('ac','Cooling'), ('acoff','Stop'), (' heeting','heating'), ('Joshitsu','dehumidifying'), ('ron','radio'), ('r1','R1'), ('r2','R2'), (' r3','R3'), ('r4','R4'), ('r5','R5'), ('r6','R6'), ('r7','R7'), (' r8','R8'), ('r9','R9'), ('r0','R0'), ('R +','+'), ('R-','-'), ( 'r>','>')]
@route('/')
@view('index')
def home():
return dict(
year=datetime.now().year,app="/app"
)
@route('/home')
@view('home')
def home1():
return dict(
year=datetime.now().year,js=js,app="/app"
)
@route('/contact')
@view('contact')
def contact():
return dict(
title='Contact',
message='Your contact page.',
year=datetime.now().year,app="/app"
)
@route('/about')
@view('about')
def about():
return dict(
title='About',
message='Your application description page.',
year=datetime.now().year,app="/app"
)
def mq(idx):
url='https://api.beebotte.com/v1/data/write/HomeControl/cmd?token={mq token}'
r=requests.post(url,{'data':idx})
@route('/click/<idx>')
def click(idx):
mq(idx)
return idx
The view template is
lyout.tpl
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="Cache-Control" content="no-cache">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title }} - My Bottle Application</title>
<link rel="stylesheet" type="text/css" href="{{app}}/static/content/bootstrap.min.css" />
<link href="{{app}}/static/content/jumbotron.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="{{app}}/static/content/site.css" />
<script src="{{app}}/static/scripts/modernizr-2.6.2.js"></script>
<script src="{{app}}/static/scripts/jquery-1.10.2.js"></script>
<script src="{{app}}/static/scripts/bootstrap.js"></script>
<script src="{{app}}/static/scripts/respond.js"></script>
</head>
<body>
<nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark">
<a class="navbar-brand" href="#">Boostrap4</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarsExampleDefault">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="/home">HomeControl</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/about">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/contact">Content</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="http://example.com" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
<div class="dropdown-menu" aria-labelledby="dropdown01">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</li>
</ul>
<form class="form-inline my-2 my-lg-0">
<input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
</form>
</div>
</nav>
<div class="container body-content">
{{!base}}
<hr />
<footer>
<p>© {{ year }} - My Bottle Application</p>
</footer>
</div>
</body>
</html>
{{app}}Is used to adjust the directory. css,Use the app variable to access the static folder containing javascript routes.Pass from py. The following app='/app'
@route('/')
@view('index')
def home():
return dict(
year=datetime.now().year,app="/app"
)
Deploy with ftp etc. and app.If you pass the execution right to py
$ chmod 700 app.py
$ ls -al
-rwx------ 1 sub.jp-hrd LolipopUser 134 2019-11-18 14:08 app.py
-
###The source code is
https://github.com/yutakahirata/lolipop2019.git
Recommended Posts