DEV Community

ColeDrain
ColeDrain

Posted on

How I ran Django on my android phone βŒπŸ’»

How I ran Django on my android phone...

Yeah, it seems weird coding with your phone, but right now I don't have an option, so if you are like me or you just fancy the idea, you can also do this. This is not an introduction to Django tutorial but how to work on Django with your android.


First we need something like a Linux terminal(or CLI) for android. Lucky for us, there is a terminal emulator on Google play store called Termux, so head to playstore and install it.
Link:termux


Okay, so you have installed it, what next?
So basically you can do whatever you could do on a Linux terminal now with this app(create directories, move files, change directory). This is how Termux looks like.

Alt Text

So let's roll in. Enter this command to view where Termux saves your files.

$ pwd

Alt Text
So that's where Termux saves your files, but the problem is you can't access that folder because of safety issues.

So to be able to access your files..
run this command

$ termux-setup-storage

And allow permission to storage in the popup shown.
Alt Text
Now change directory to your internal shared storage by running this command.

$ cd /sdcard

N:B this command doesn't point to your external SD card but your internal SD card(storage).


Then let's create a folder to store our Django projects, let's call it django_projects.
So run this command.

$ mkdir django_projects

$ cd django_projects


Now let's install python
To install python, run this

$ pkg install python

To check if python is installed, run the python command to enter python console.

$ python

N:B Use ctrl + z to exit the terminal. Termux app comes with a ctrl key.


Let's create a project called mysite
So still in that django_projects, run this commands.

$ mkdir mysite

$ cd mysite

We need a virtual environment to avoid dependencies clash. So let's install a virtual environment, run this command.

$ pip install virtualenv

After installing it, run

$ virtualenv venv

to create a virtual environment.. Then activate the virtual environment by running (note the full stop)

$ . venv/bin/activate


Now we have a virtual environment, let's install Django. run..

$ pip install Django

Okay, so Django is installed in our venv, let's create a Django project. run..

$ django-admin startproject hello .

(note the full stop)

Then let's run migrations..

$ python manage.py migrate

You can then run the server..

$ python manage.py runserver

voilΓ , go to your phone browser and open http://127.0.0.1:8000 and you should see this.
Alt Text

You can always view your files by going to your file manager and searching for django_projects folder.

Feel free to indulge me, if any issues.

Latest comments (32)

Collapse
 
ranjandel profile image
ranjan-del

.../django1/mysite $ virtualenv venv
PermissionError: [Errno 1] Operation not permitted: '/data/data/com.termux/files/usr/bin/python3' -> '/storage/emulated/0/django1/mysite/venv/bin/python'

Any one help

Collapse
 
apoorvashukla profile image
Apoorva Kumar Shukla

hi

Collapse
 
apoorvashukla profile image
Apoorva Kumar Shukla

Collapse
 
apoorvashukla profile image
Apoorva Kumar Shukla
Collapse
 
apoorvashukla profile image
Apoorva Kumar Shukla
Collapse
 
apoorvashukla profile image
Apoorva Kumar Shukla

Hello

Collapse
 
darwinfont profile image
darwinfont

Me gustaria saber si desde esta app seria posible instalar Node js

Collapse
 
darwinfont profile image
darwinfont

Tengo una duda desde esta app tambien seria posible instalar node js

Collapse
 
gatsbysex profile image
Matz

$ virtualenv env
PermissionError: [Errno 1] Operation not permitted: '/data/data/com.termux/files/usr/bin/python3' -> '/storage/emulated/0/aamydjango/Django/env/bin/python'

Some comments may only be visible to logged-in visitors. Sign in to view all comments.