How To Develop A Django Website Using Termux And Android ? Before we dive into designing a Django website using android let me explain what is python and Django.
What is Python
Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.
Its high-level built in data structures, combined with dynamic typing and dynamic binding, make it very attractive for Rapid Application Development, as well as for use as a scripting or glue language to connect existing components together.
Python’s simple, easy to learn syntax emphasizes readability and therefore reduces the cost of program maintenance. Python supports modules and packages, which encourages program modularity and code reuse.
The Python interpreter and the extensive standard library are available in source or binary form without charge for all major platforms, and can be freely distributed.
Often, programmers fall in love with Python because of the increased productivity it provides.
Since there is no compilation step, the edit-test-debug cycle is incredibly fast. Debugging Python programs is easy: a bug or bad input will never cause a segmentation fault.
Instead, when the interpreter discovers an error, it raises an exception. When the program doesn’t catch the exception, the interpreter prints a stack trace.
A source level debugger allows inspection of local and global variables, evaluation of arbitrary expressions, setting breakpoints, stepping through the code a line at a time, and so on.
The debugger is written in Python itself, testifying to Python’s introspective power.
On the other hand, often the quickest way to debug a program is to add a few print statements to the source: the fast edit-test-debug cycle makes this simple approach very effective.
What is Django
Django is a high-level Python web framework that enables rapid development of secure and maintainable websites.
Built by experienced developers, Django takes care of much of the hassle of web development, so you can focus on writing your app without needing to reinvent the wheel.
It is free and open source, has a thriving and active community, great documentation, and many options for free and paid-for support. if you still want to know more about django you can check it here
How to design a django website using termux and android.
Developing or runnning a django website has become very easy on PC or Phone if and only if you stick to the steps and proceduals outlined.
In this post we would be using Android phone, termux and coders keyboard to develop our django webapp
Softwares or prerequisite required to develop a django website on your phone
1.Install Coders keyboard
2.Install Termux
3.Install python3 or python2
4.Create a virtual environment
5.install django
6.Start a project
7.start an app
Installations of coder’s board
Clickhereto install coders board or go to playstore on your android phone and search for coder’s board then hit install,then wait until the installation is complete.
Installation of Termux
For the following commands to work on your phone it’s recommended that you install termux according to the process used here. learn how to install termux on Android or go to google and search for termux.
Now after installing termux as indicated here then paste in this command
"pkg install python3"
in your terminal with out quote
After the installation of python then type
python
to see the python version,if you didn’t install python the right way you will see an error when you type python. After the successful installation python then you have to create a virtaul environments that will hold our project we are about to create.
python -m venv my_venv
After creating a virtual environment you will have to activate it by using this command
source my_venv/bin/activate
Let me explain,We installed python to access the framework django then we created virtual environment my_venv is the name of the environment then the rest is the command for creating the environment.You can name it anything you want.
Now it is time to install django type in the command below.
pip install django
You have to install a parkage for timezone, If you didn’t install it you might not be able to access your django admin
How to install setoolkits in nethunter kali linux
pip install tzdata
Boom it time to create our website, for the sake of this tuttorial we will name it mysite and name the app as myapp.
./manage.py startproject mysite
run “cd mysite” without quote
./manage.py startapp myapp
After creating your app you have to run
./manage.py runserver
This will start your new website on localhost port 8000,e.g http://127.0.0.1:8000 copy this and paste it in your browser, then boom that is your first website, Now let us talk about making homepage dynamic rather than static pages
Now you have successfully installed your first Django website is time to create a dynamic URL.
Quit the process by running Ctrl^c then you have to install nano. But by default you should have nano, but just enter the command
apt install nano
then you should see requirements already satisfied. run ls to see the folder you have, in my own i will see;my site, my app and others things.
First lets configure our template in other to use template in this post.run
cd mysite ls nano settings.py
nano settings.py is to open the settings.py with text editor then in template line enter
'os.path.join(BASE_DIR,'template')'
This will help in configuaration of template.after you have type in the command as in the image above then run
cd .. ls
then you are in the project directory,then run
cd myapp && nano urls.py
follow the image below and configure your own like that after you are done press ctrl^x i.e ctrl plux x then select y to save and click enter to exit
.
Now you have to write a view function in views.py
cd .. cd myapp nano views.py
then edit your views like mine below
now save and exit it by pressing ctrl x and select y then press enter
Go to your app root directory by pressing cd .. ls you will see that you have myapp and mysite, now you will make a directory called template.
mkdir template cd template touch index.html nano index.html
Inside the index.html just write “welcome to my site
” after we will use bootstrap to make our page nice.
Now run
./manage.py runserver
to start the web app , Good that we have a nice and dynamic website.
You can leave a comment below