2  Django Server

2.1 Django Setup On Server

Setting up a Django application on Ubuntu 24.04 LTS involves preparing the development environment and creating a Django project. Here’s how you can quickly set up Django on this platform.

Pip and venv are needed for Django projects:

apt install python3-pip
apt install python3.12-venv
  1. Switch to Your Normal User:

    If you’re currently logged in as the root user, switch to a normal user:

    su - username

    Replace username with your actual user account name.

  2. Navigate to the Project Directory:

    Make sure you’re in a directory where your user has write permissions. You can create a directory for your projects if it doesn’t exist:

    mkdir ~/DjangoProjects
    cd ~/DjangoProjects
  3. Create the Project Directory and Set Up a Virtual Environment:

    Create a new directory for your project, then set up and activate a virtual environment inside it:

    mkdir myproject
    cd myproject
    python3 -m venv .venv
    source .venv/bin/activate
  4. Create the Django Project:

    With the virtual environment activated, create your Django project:

    pip install django
    django-admin startproject myproject .

2.2 Running Django Server

2.2.1 Step 1. Update Settings:

Open your settings.py file:

  • Add your domain name: ALLOWED_HOSTS=['*']
  • To serve stiatic files: STATIC_ROOT = BASE_DIR / 'static' and DEBUG = True

2.2.2 Step 2: Run the Server

With your settings configured, start the Django development server using your public IP address and a port:

python manage.py collectstatic
python manage.py runserver 0.0.0.0:8888
  • 0.0.0.0 makes Django listen on all network interfaces, allowing access from external IP addresses.
  • 8888 is the default port for Django’s development server; you can use a different port if needed.

2.2.3 Step 3: Access the Server

With the server running, you can access your Django application by entering the server’s IP address and port in a web browser:

http://cyber.mrchen.store:8888

2.3 Account Management

2.3.1 Add Developers To Ubuntu Linux

sudo useradd -m -s /bin/bash jimmy
echo "jimmy:jimmy2024" | sudo chpasswd
sudo useradd -m -s /bin/bash justin
echo "justin:justin2024" | sudo chpasswd

2.3.2 Add Admin Users To Django

python manage.py createsuperuser
# username: jimmy
# password: jimmy2024