Skip to content

How to Deploy DjangoBlog with Python Project in uWSGI Mode

Deploy DjangoBlog using Python Project in uWSGI mode

Tutorial Environment:

  • Python 3.14.3
  • MySQL 8.0.36
  • Npm
  • Nginx
  • aaPanel 8.2.0 Beta Version

Install Node.js and verify npm command

  1. Search for and install Node.js version manager in the App Store, then install Node.js (e.g., select version v24.14.0) alt text

  2. Configure command-line environment variables to use the npm command alt text

  3. Verify the npm command

    node -v
    npm -v

    alt text

Install MySQL 8.0.36 and Create Database for DjangoBlog

  1. MySQL installation steps are omitted here

  2. Create database: djangoblog

    • Note: Select character set utf8mb4 when creating

    • Please save the database name and password for later use alt textalt text

Install Python 3.14 and Create Virtual Environment

  1. Install Python 3.14.3 in aaPanel's Python Project:

    WebSite -> Python Project -> Python Environment -> Version management -> All version

    alt text

    • Select the version to install (installation process omitted here)
  2. Create a virtual environment for Python 3.14.3

    Python Project -> Python Environment -> Create virtual environmentalt textalt text

    • Select Python 3.14.3 to create a virtual environment named: testenv

Clone the DjangoBlog Project:

  1. First install git

    • RedHat/CentOS:
    yum install git -y
    • Debian/Ubuntu:
    apt-get update -y && apt-get install git -y
  2. Clone the DjangoBlog repository

    cd /www/wwwroot/
    git clone https://github.com/liangliangyy/DjangoBlog

    alt text

Modify DjangoBlog Configuration Information

Navigate to the DjangoBlog directory, then enter the djangoblog subdirectory and modify the configuration file: settings.py

/www/wwwroot/DjangoBlog/djangoblog/settings.py
  1. Modify database configuration

    Comment out the original database configuration, then add the following content. Note to replace with your database name, username, and password, and pay attention to the case sensitivity of the database information.

    Use the MySQL database information created earlier

    python
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.mysql',
            'NAME': 'djangoblog',
            'USER': 'djangoblog',
            'PASSWORD': 'zpnnDpdZGMnAMFFe',
            'HOST': 'localhost',
            'PORT': 3306,
            'OPTIONS': {'charset': 'utf8mb4'},
        }
    }

    alt text

  2. Modify language and time zone

    python
    LANGUAGE_CODE = 'en'
    TIME_ZONE = 'America/New_York'

    alt text

Create DjangoBlog Project in Python Project

  1. Enter Python Project WebSite -> Python Project -> Add Projectalt text

  2. Add DjangoBlog project alt text

    • First select the project directory, which will automatically identify the project type as: django and detect the uwsgi startup file and other information

    • Fill in the project name: DjangoBlog

    • Enter the port number: 8088

    • Select the virtual environment: testenv

  3. After confirmation, the system will automatically install the dependent environment alt text

  4. Completion of dependency installation alt text

Initialize DjangoBlog

CAUTION

You must enter the virtual runtime environment first

  1. Enter the virtual runtime environment of the DjangoBlog project with root privileges

    • Method 1: Directly enter through the project Terminalalt text

    • Method 2: Get the Python virtual environment path and manually enter it in the terminal alt text Example: Replace the virtual environment path with your own

      cd /www/wwwroot/DjangoBlog
      source /www/server/pyporject_evn/testenv/bin/activate

      alt text

  2. Initialize the database with root privileges

    python manage.py makemigrations

    alt text

    python manage.py migrate

    alt text

  3. Create superuser account

    • You will be prompted to enter a username, email address, and password. Note that the password cannot be too simple.
    python manage.py createsuperuser

    alt text

  4. Build front-end resources

    • Navigate to the front-end directory
    cd /www/wwwroot/DjangoBlog
    cd frontend
    • Install dependencies (required for first run)
    npm install

    alt text

    • Build production environment resources
    npm run build

    alt text

    • Return to the DjangoBlog project root directory
    cd /www/wwwroot/DjangoBlog
  5. Collect static files and compress

    • Collect static files
    python manage.py collectstatic --noinput

    alt text

    • (Optional) Compress files
    python manage.py compress --force

    alt text

    • (Optional) Generate test data
    python manage.py create_testdata

Restart DjangoBlog Project and Test Access

  1. Restart the DjangoBlog project alt text

  2. Open the port of the DjangoBlog project (8088 in this case) in the system firewall and the server provider's security group

  3. Test access: http://Your-IP:8088alt text

Production-Grade Deployment

Nginx serves static files, uWSGI handles dynamic requests

  1. Add domain name to DjangoBlog project alt text

  2. Enable mapping to generate site configuration file alt text

  3. Configure static file rules alt text

        location /static/ {
            alias /www/wwwroot/DjangoBlog/collectedstatic/;
            expires max;
            access_log        off;
            log_not_found     off;
        }
        location /media {
            alias /www/wwwroot/DjangoBlog/uploads/;
            expires max;
        }
        location ~ \.py$ {
            return 403;
        }
  4. Deploy SSL certificate

  5. Test access: https://domain.comalt text