Lesson 2: Install Django on Ubuntu + Create Your First Project
π Introduction
In this lesson, you will install Django on your Ubuntu server, create your development environment, and run your first Django project online using your serverβs IP address. By the end of the lesson, you will have two working pages:
/β Success / Home page/about/β Simple About page
This lesson is intentionally beginner-friendly, with detailed steps and a troubleshooting section based on real issues that learners often face.
π§° 1. Update Your Server & Install Required Tools
SSH into your server:
ssh youruser@your-server-ip
Update and install required packages:
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3 python3-venv python3-pip git
Verify:
python3 --version
pip3 --version
π 2. Create a Root Folder for All Django Projects
A good habit is to keep all your Django projects in one folder:
mkdir -p ~/django-projects
cd ~/django-projects
Create a new project folder:
mkdir lesson2_project
cd lesson2_project
π§ͺ 3. Create & Activate a Python Virtual Environment
A virtual environment ensures every project has its own isolated dependencies:
python3 -m venv venv
source venv/bin/activate
You should now see:
(venv)
If you re-login later, reactivate with:
source ~/django-projects/lesson2_project/venv/bin/activate
π’ 4. Install Django
Inside the active venv:
pip install --upgrade pip
pip install django
Check version:
python -m django --version
π οΈ 5. Create Your Django Project
Use the name config for the base settings:
django-admin startproject config .
Now your folder contains:
manage.py
config/
venv/
π 6. Run Django on Your Server (Port 1011)
Djangoβs development server can run on any port.
Weβll use 1011:
python manage.py runserver 0.0.0.0:1011
Open in your browser:
http://YOUR_SERVER_IP:1011
You should see:
π βThe install worked successfully!β
ποΈ 7. Create Your First App
Every Django feature lives inside an app.
Create one called core:
python manage.py startapp core
π§© 8. Register the App
Open your settings:
nano config/settings.py
Find INSTALLED_APPS and add:
'core',
Save and exit.
β¨ 9. Create Your First View (Home Page)
Open:
nano core/views.py
Add:
from django.http import HttpResponse
def hello(request):
return HttpResponse("""
<h1 style='text-align:center;color:#007bff;'>Success!</h1>
<p style='text-align:center;'>I finished Lesson 2 in Django!</p>
<p style='text-align:center;font-size:14px;color:gray;'>
View generated by Webmaster and More's Django server.
</p>
""")
π 10. Add URLs for Your App
Create:
nano core/urls.py
Insert:
from django.urls import path
from . import views
urlpatterns = [
path('', views.hello, name='hello'),
]
Then connect it in config/urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('core.urls')),
]
π 11. Create the /about/ Page
In core/views.py:
def about(request):
return HttpResponse("""
<div style='text-align:center;padding:40px;'>
<h1 style='color:#0066ff;'>My Path to Full Stack</h1>
<h3>This Django training will help me upgrade to Full Stack Developer.</h3>
<p>Setting clear goals is the first step to achieving them. Keep pushing forward!</p>
<p style='font-size:14px;color:gray;'>
View generated by webmasterandmore's Django server.
</p>
</div>
""")
Then add the URL:
path('about/', views.about, name='about'),
π₯οΈ 12. Visit Your Pages
Home page:
http://YOUR_SERVER_IP:1011/
About page:
http://YOUR_SERVER_IP:1011/about/
Both should work now.
π Troubleshooting (Beginner-Friendly)
These are real errors you may encounter (and how to fix them).
β 1. Browser shows HTTPS error (ERR_SSL_PROTOCOL_ERROR)
Cause: You used https:// instead of http://.
Fix:
Use:
http://YOUR_SERVER_IP:1011
β 2. DisallowedHost at /
Error:
Invalid HTTP_HOST header β¦
Cause: You didnβt add your server IP to ALLOWED_HOSTS.
Fix:
ALLOWED_HOSTS = ['YOUR_SERVER_IP', 'localhost', '127.0.0.1']
β 3. Port already in use
Error:
Error: That port is already in use
Fix: Choose a different port:
python manage.py runserver 0.0.0.0:1012
Check used ports:
sudo ss -tulnp
β 4. favicon.ico 400 errors
Ignore these β browsers request /favicon.ico automatically.
π Quick Exercise for Lesson 2
- What is the purpose of creating a virtual environment?
- How do you create a new Django project using
django-admin? - How do you start the development server on port 1011?
- In which file do you register your newly created Django app?
- What is the purpose of
core/urls.py?
Answers PDF: β Delivered in previous message
(lesson2_answers.pdf)
π‘ Homework for Lesson 2
1. Make sure your home page works on port 1011.
2. Create a custom βSuccessβ message.
Add your name + your company.
3. Take a screenshot of your working page.
4. Create the /about/ page.
(PDF contains the required answer.)
π Conclusion
You have successfully:
- Installed Django on Ubuntu
- Created a project and an app
- Built your first dynamic pages
- Solved common beginner issues
- Hosted your project on your own server
This completes Lesson 2 of the Django Full Stack Developer Path.