When deploying a django webapp to Linux servers, Nginx/Apache as server, PostgreSQL/MySQL as database are preferred. For this tutorial, we will be using django development server with SQLite database.
First install SSHDroid app on Android. It will start ssh server on port 2222. If android phone is rooted, we can run ssh on port 22.
Now install QPython. This comes bundled with pip, which will install required python packages.
Instead of installing these two apps, we can use Termux, GNURoot Debian or some other app which provides Linux environment in Android. These apps will provide
apt package manager, which can install
I have used django-bookmarks, a simple CRUD app to test this setup. We can use rsync or adb shell to copy django project to android.
rsync -razP django-bookmarks :$USER@$HOST:/data/local/
Now ssh into android, install django and start django server.
$ ssh -v $USER@$HOST
$ python -m pip install django $ cd /data/local/django-bookmarks $ python manage.py runvserver
This will start development server on port 8000. To share this webapp with others, we will expose it with serveo.
$ ssh -R 80:localhost:8000 serveo.net Forwarding HTTP traffic from https://incepro.serveo.net Press g to start a GUI session and ctrl-c to quit.
Now we can share our django app with anyone.
I have used Moto G4 Plus phone to run this app. I have done a quick load test with Apache Bench.
ab -k -c 50 -n 1000 \ -H "Accept-Encoding: gzip, deflate" \ http://incepro.serveo/list/
It is able to server 15+ requests concurrently with an average response time of 800ms.
We can write a simple shell script or ansible playbook to automate this deployment process and we can host a low traffic website on an android phone if required.