Android Smart Phoneをpythonを使ってWeb Serverにする。

#Android Smart Phoneをpythonを使ってWeb Serverにする。
Pydroid 3 - IDE for Python 3を使ったけど手を火傷して使用中止!

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/49fbf93d-cc02-b4c1-5787-62fa90f0ead6.png)


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/c7836d02-3c4e-0619-c13e-38db06b40d7a.png)
##UserLandをGoogle Playよりインストールする。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/dff3557e-ccd1-a67f-f0dd-73d102093427.png)

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/d5bafb24-45f8-aac8-82fe-2b0257f3a59a.png)


##sshでログインする。Rloginを使っています。Port 2022です。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/7483720d-927a-ddfa-719c-47ddc7cec815.png)

linux画面が立ち上がります。
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/7f5cd6d7-d0e6-81ca-9f91-58b8057f179f.png)

##環境整備します。vim editorを使えるようにします。

```
sudo apt update
sudo apt upgrade -y
sudo apt install -y vim

vim test.c
#include <stdio.h>
int main(){
        printf("hello world\n");
}

hirata@localhost:~$ cc test.c
hirata@localhost:~$ ./a.out
hello world
hirata@localhost:~$
```
###hello worldが出ればOK!

##pythonの導入と確認

```
sudo apt update
sudo apt install python3
sudo apt install python3-pip

hirata@localhost:~$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
```
###bottoleの導入
```
sudo pip3 install bottle
```
### テストプログラムの作成

```web.py
from bottle import route, run
@route('/')
def root():
    str=""
    for i in range(10):
        str=str+"<h1>Hello %d</h1>"%i
    return str
@route('/hello')
def hello():
    return "<h1>Hello World!</h1>"
run(host='192.168.1.16', port=8080, debug=True)
```

#### 実行
![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/4209c7ce-a62b-70ee-bbab-7d0ed8941243.png)

##Visual Studio 2019で作成されたテンプレートの実行

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/274715/95bbe662-ddd6-211a-4aa8-ca07d03ce378.png)

```
.
|-- 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
|       |-- _references.js
|       |-- 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
`-- views
    |-- about.tpl
    |-- contact.tpl
    |-- index.tpl
    `-- layout.tpl
```
```app.py
"""
This script runs the application using a development server.
"""

import bottle
import os
import sys

# routes contains the HTTP handlers for our server and must be imported.
import routes

if '--debug' in sys.argv[1:] or 'SERVER_DEBUG' in os.environ:
    # Debug mode will enable more verbose output in the console window.
    # It must be set at the beginning of the script.
    bottle.debug(True)

def wsgi_app():
    """Returns the application to make available through wfastcgi. This is used
    when the site is published to Microsoft Azure."""
    return bottle.default_app()

if __name__ == '__main__':
    PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
    STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static').replace('\\', '/')
    HOST = os.environ.get('SERVER_HOST', 'localhost')
    try:
        PORT = int(os.environ.get('SERVER_PORT', '5555'))
    except ValueError:
        PORT = 5555

    @bottle.route('/static/<filepath:path>')
    def server_static(filepath):
        """Handler for static files, used with the development server.
        When running under a production server such as IIS or Apache,
        the server should be configured to serve the static files."""
        return bottle.static_file(filepath, root=STATIC_ROOT)

    # Starts a local test server.
    HOST,PORT="192.168.1.16",8080
    bottle.run(server='wsgiref', host=HOST, port=PORT)

```

```routes.py
"""
Routes and views for the bottle application.
"""

from bottle import route, view
from datetime import datetime

@route('/')
@route('/home')
@view('index')
def home():
    """Renders the home page."""
    return dict(
        year=datetime.now().year
    )

@route('/contact')
@view('contact')
def contact():
    """Renders the contact page."""
    return dict(
        title='Contact',
        message='Your contact page.',
        year=datetime.now().year
    )

@route('/about')
@view('about')
def about():
    """Renders the about page."""
    return dict(
        title='About',
        message='Your application description page.',
        year=datetime.now().year
    )

```