Preparation:
Install Termux
Get Termux from the Google Play Store.
Update Packages:
Launch Termux and update its packages with the command:
pkg update && pkg upgrade
Step 1: Install Python
Install Python:
Use the following command in Termux:
pkg install python
Step 2: Install Django
Using pip: Install Django with pip by running:
pip install django
Step 3: Start a New Django Project
Create Project: Initiate a new Django project using:
django-admin startproject mysite
(Replace ‘mysite’ with your project name.)
Step 4: Run the Django Server
Navigate to Directory: Change to your project directory:
cd mysite
Run Server: Start the Django server with:
python manage.py runserver
Step 5: Accessing Your Site
Default Port: The server runs on port 8000. Access it at localhost:8000 using a web browser. If on mobile, use the same device to access the server.
Step 6: Modify the View
Edit views.py: Create a simple view in your app. Example:
from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. You're at the polls index.")
Update urls.py: Create a URL pattern for your view.
Step 7: Create an App
Django Apps: Start your first Django app with:
python manage.py startapp polls
Conclusion:
You’ve now laid the foundation of your Django project in Termux on Android. This guide covers the basics, from installation to starting a simple server. Future tutorials will explore advanced topics like databases, models, and front-end development. Remember, Termux offers a unique environment for learning and experimenting, but it has its own set of limitations. Enjoy your coding journey!