We are going to test run python Flask on mobile phone as nowadays there are mobile phones available with more CPU and RAM than it used to be generally available on laptops.
I know most of the time people need their phone to do the stuff for these phones are made. But, what about when you are working and your android with gigabytes of RAM and multi-core CPU is just sleeping and waiting for incoming text/call? what about using it as portable webserver for development environment?
So I'm going to demonstrate how to install and run python Flask micro framework on mobile phone.
Prerequisite:
apt-get install python
It's always to recommended to install virtual environment for the experiments and keeping application specific package versions separate.So let's install virtualenv package and create and activate a virtual environment called flask(you can give any name you like). Once the virtual environment activated. it will change the terminal prompt and add activated environment name, in my case as the environment name is 'flask' it has changed prompt to (flask)$.
Now as the virtual environment is activated, we can install required python packages and these packages will be restricted to 'flask' virtual environment. In our case we just need Flask package so will install only 'flask' using pip utility.
pip install virtualenv
virtualenv flask
source .flask/bin/activate
pip install Flask
cat app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "My mobile web server!"
if __name__ == "__main__":
app.run(host='0.0.0.0')
Next will write a quick test Flask application and run to test if it's working. below command will start Flask inbuilt webserver on port 5000.
python app.py
Test it on you mobile web browser using : http://localhost:5000
To access it on laptop we have to connect laptop to mobile using mobile hotspot and using mobile ip. In my case the IP address is : 192.168.43.1
To check mobile IP address, activate mobile hot-spot on android and check IP access using ifconfig command.
ifconfig wlan0
What next? install git and pull your your python Flask app code and run it on mobile.👀
I know most of the time people need their phone to do the stuff for these phones are made. But, what about when you are working and your android with gigabytes of RAM and multi-core CPU is just sleeping and waiting for incoming text/call? what about using it as portable webserver for development environment?
So I'm going to demonstrate how to install and run python Flask micro framework on mobile phone.
Prerequisite:
- Terminal access( no need of root access): I'm using Termux
- Python 2 or 3
- pip
- Flask
apt-get install python
It's always to recommended to install virtual environment for the experiments and keeping application specific package versions separate.So let's install virtualenv package and create and activate a virtual environment called flask(you can give any name you like). Once the virtual environment activated. it will change the terminal prompt and add activated environment name, in my case as the environment name is 'flask' it has changed prompt to (flask)$.
Now as the virtual environment is activated, we can install required python packages and these packages will be restricted to 'flask' virtual environment. In our case we just need Flask package so will install only 'flask' using pip utility.
pip install virtualenv
virtualenv flask
source .flask/bin/activate
pip install Flask
cat app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return "My mobile web server!"
if __name__ == "__main__":
app.run(host='0.0.0.0')
Next will write a quick test Flask application and run to test if it's working. below command will start Flask inbuilt webserver on port 5000.
python app.py
Test it on you mobile web browser using : http://localhost:5000
To access it on laptop we have to connect laptop to mobile using mobile hotspot and using mobile ip. In my case the IP address is : 192.168.43.1
To check mobile IP address, activate mobile hot-spot on android and check IP access using ifconfig command.
ifconfig wlan0
What next? install git and pull your your python Flask app code and run it on mobile.👀