[LINUX] Turn your Android Smart Phone into a Web Server using python.

Turn your Android Smart Phone into a Web Server using python.

I used Pydroid 3 --IDE for Python 3, but I burned my hand and stopped using it!



Install UserLand from Google Play.



Log in with ssh. I'm using Rlogin. It is Port 2022.


The linux screen will appear. image.png

We will improve the environment. Enables the use of 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

OK if hello world appears!

Introduction and confirmation of 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.

Introduction of bottle

sudo pip3 install bottle

Creating a test program


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



Run templates created in Visual Studio 2019


|-- 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


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.

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')
        PORT = int(os.environ.get('SERVER_PORT', '5555'))
    except ValueError:
        PORT = 5555

    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.
    bottle.run(server='wsgiref', host=HOST, port=PORT)


Routes and views for the bottle application.

from bottle import route, view
from datetime import datetime

def home():
    """Renders the home page."""
    return dict(

def contact():
    """Renders the contact page."""
    return dict(
        message='Your contact page.',

def about():
    """Renders the about page."""
    return dict(
        message='Your application description page.',

Recommended Posts

Turn your Android Smart Phone into a Web Server using python.
Port forwarding your web server using iptables
Build a web server on your Chromebook
Set up a local web server in 30 seconds using python 3's http.server
Book updated: Evolving into a "decent web server"
Start a simple Python web server with Docker
Create a web map using Python and GDAL
Launch a web server with Python and Flask
(Python) Try to develop a web application using Django
Build a Python environment on your Mac using pyenv
Learning neural networks using Chainer-Creating a Web API server
[Python] I tried running a local server using flask
[Python] Mask the image into a circle using Pillow
How to host web app backend processing in Python using a rental server subdomain
HTTP server and HTTP client using Socket (+ web browser) --Python3
Build a web API server at explosive speed using hug
Operate your browser using the Selenium Web Driver Python bindings
Build a python environment on CentOS 7.7 for your home server
Web scraping using Selenium (Python)
Let's turn PES analysis software into a WEB application! First step!
I made a poker game server chat-holdem using websocket with python
Let's make a web chat using WebSocket with AWS serverless (Python)!
I made a Chatbot using LINE Messaging API and Python (2) ~ Server ~
Creating a web application using Flask ②
I made a Line-bot using Python!
Create a python GUI using tkinter
Drawing a silverstone curve using python
Creating a web application using Flask ①
Creating a web application using Flask ③
Creating a web application using Flask ④
Let's turn PES data analysis software into a web application! Second step!
Try using the Python web framework Django (1)-From installation to server startup
Connect your SQL Server database to Alibaba Cloud Function Compute using Python
[python] How to add RDF triples to your own Fuseki server using rdflib
Start a web server using Bottle and Flask (I also tried using Apache)
I want to make a web application using React and Python flask
Install Python3 and Django on Amazon Linux (EC2) and run your web server
Implement a simple application with Python full scratch without using a web framework.