โ† Back to Blog
CoursesDjango

Lesson 2: Install Django on Ubuntu + Create Your First Project

ยท4 min read

๐Ÿš€ 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

  1. What is the purpose of creating a virtual environment?
  2. How do you create a new Django project using django-admin?
  3. How do you start the development server on port 1011?
  4. In which file do you register your newly created Django app?
  5. 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.