Django: Steps to update web server with local changes

Applies largely to a Django project hosted on a remote server

Prateek Verma / 05 June 2022

web development django computational tiny guide python

featured photo for Django: Steps to update web server with local changes

  1. Log into your web server using ssh.
  2. Sync local files to web server.
    • using FTP (not covered here)
    • using git
      • add your identity to the ssh-agent (assuming you have set up remote login to your web server's git repo already)
        ssh-add ~/.ssh/<your_identity_filename>
      • enter passphrase when prompted
      • navigate to the dir where your project's git repo is located
        cd /path/to/project
      • pull changes from the GitHub (or remote) repo. Note that your local changes should have already pushed the changes to the GitHub (remote) repo.
        git pull origin main
  3. Activate Python's virtual environment on your web server that has Django installed.
    source /path/to/venv/bin/activate
  4. Collect static files if changes to static files were made. You should already in the Django project's root directory that contains the file.
    python collectstatic
  5. Execute migrations if changes to models were made. Note that migration files should have already been created and pushed to the GitHub (remote) repo.
    python migrate
  6. Restart the web server.
    sudo service apache2 restart or an equivalent command for your web server.

Last updated on June 01, 2023

Recent Posts